Skip to content

Wrong return value of JsonObject::set(key, "string") #350

@softerra

Description

@softerra

I may misunderstand the sense of the return value of JsonObject::set() but hope it means successfulness of the operation, doesn't it?

If so the real value the method returns for setting string values is wrong.

Just try:
bool r = jso.set("key", "value");

The result will be false.

This happens because the underlying JsonObject::setNodeValue(, string) doesn't return successfulness of the operation, meaning the string allocation. Instead, it returns the value being set converted to bool.

template <>
inline bool JsonObject::setNodeValue(node_type *node, String &value) {
node->content.value = _buffer->strdup(value);
return node->content.value;
}

As I see the method (and its const String& variation) should be like that:

template <>
inline bool JsonObject::setNodeValue(node_type *node, String &value) {
char *dup = _buffer->strdup(value);
node->content.value = dup;
return dup != NULL;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions