mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
add_string_to_string: Don't fail if @from is empty.
Old versions of add_string_to_string returned the target string unmodified if from->source pointed to a null character, which usually meant that the source string was empty. That was changed in commit 5e18576391f75ad84e04f9c8a30b93d08f0b92ab on 2004-11-03 so that add_string_to_string instead returned NULL in that situation. The change seems to have been inadvertent. I'm now reverting that change and also making add_string_to_string check the emptiness of the source string based on the stored length only, rather than on any null characters. So the function can now also be used with non-C strings containing embedded null characters. Note that the previous version did not completely prevent embedded null characters either, because it checked only the first character.
This commit is contained in:
parent
2ac31b6144
commit
4a23d7fd82
@ -326,7 +326,7 @@ add_string_to_string(struct string *string, const struct string *from)
|
|||||||
check_string_magic(string);
|
check_string_magic(string);
|
||||||
check_string_magic(from);
|
check_string_magic(from);
|
||||||
|
|
||||||
if (!*from->source) return NULL;
|
if (!from->length) return string; /* optimization only */
|
||||||
|
|
||||||
return add_bytes_to_string(string, from->source, from->length);
|
return add_bytes_to_string(string, from->source, from->length);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user