]> git.ipfire.org Git - thirdparty/ipxe.git/commit
[hci] Fix semantics of replace_string() to match code comments
authorMichael Brown <mcb30@ipxe.org>
Wed, 17 Apr 2024 14:45:36 +0000 (15:45 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 17 Apr 2024 14:55:28 +0000 (15:55 +0100)
commitb01781a2b8fb29669d9a610bfb323fb8a6960612
tree4c621dd4ab80ec6e6c7a2e408efef1684ab93875
parentcb95b5b378b1a61d10770965d82dba535b6be242
[hci] Fix semantics of replace_string() to match code comments

The comments for replace_string() state that a successful return
status guarantees that the dynamically allocated string pointer is no
longer NULL (even if it was initially NULL and the replacement string
is NULL or empty).  This is relied upon by readline() to guarantee
that it will always return a non-NULL string if successful.

The code behaviour does not currently match this comment: an empty
replacement string may result in a successful return status even if
the (single-byte) allocation fails.

Fix up the code behaviour to match the comments, and to additionally
ensure that the edit history is filled in even in the event of an
allocation failure.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/hci/editstring.c