Skip to content

Some strings seem to have bogus data at the end (core 2.6.0 vs. core 2.4.2) #5883

Closed
@TD-er

Description

@TD-er

In ESPeasy we have some web page rendering all kinds of variables/strings as a cheat-sheet for the internal variable substitutions.
The same code built using core 2.4.2 and core 2.6.0 (both SDK 2.2.1 and SDK 2.2.2) shows different output.

Core 2.6.0:

  • %ssid% MikroTik0�$ MikroTik0�$
  • %sysname% CO2_defect$ CO2_defect$
  • {E} € %e2%82%ac�$
  • € € %e2%82%ac�$

Core 2.4.2:

  • %ssid% MikroTik MikroTik
  • %sysname% CO2_defect CO2_defect
  • {E} € %e2%82%ac
  • € € %e2%82%ac

This is an example of a conversion which appears to be correct in both:

  • {Y} ¥ %c2%a5
  • ¥ ¥ %c2%a5

These are the ones giving different results (may be others, but these are noticeable)

These are the result from a call to this function:

void repl(const String& key, const String& val, String& s, boolean useURLencode)
{
  if (useURLencode) {
    s.replace(key, URLEncode(val.c_str()));
  } else {
    s.replace(key, val);
  }
}


const char euro[4] = {0xe2, 0x82, 0xac, 0}; // Unicode euro symbol
const char yen[3]   = {0xc2, 0xa5, 0}; // Unicode yen symbol
repl(F("{E}"), euro, s, useURLencode);
repl(F("€"), euro, s, useURLencode);
repl(F("{Y}"), yen, s, useURLencode);
repl(F("¥"), yen, s, useURLencode);

repl(F("%ssid%"), WiFi.SSID(), s, useURLencode);
repl(F("%sysname%"), Settings.Name, s, useURLencode);

The ones that work just fine are the ones that were converted to a String object before calling this function.
The ones that fail are all char arrays, but not all of these fail like can be seen with the "yen" conversion.

It looks like the ones that fail have an odd number of characters (e.g. the example sysname is 10 characters).
These char arrays are all 0-terminated, or else they would have given issues in core 2.4.2 too.
The ones that were converted to a String before calling this repl function, were probably padded with more zeroes due to how the String implementation now does its allocation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions