Commit Graph

14 Commits

Author SHA1 Message Date
Xavier Del Campo Romero 909d716a1e dynstr.c: Fix memory leak if realloc(3) fails
According to C99 §7.20.3.4:

If memory for the new object cannot be allocated, the old object is not
deallocated and its value is unchanged.

Therefore, a temporary pointer must be used to ensure the original
object can still be deallocated should realloc(3) return a null pointer.
2023-03-08 01:21:16 +01:00
Xavier Del Campo Romero 8e7557ef7a dynstr.c: Make zero-initialization portable 2023-03-08 01:19:21 +01:00
Xavier Del Campo Romero 0f2bf85be8 Update copyright notice 2023-03-08 01:18:47 +01:00
Xavier Del Campo Romero 601a813325 Fix lifetime issues with va_list
The standard requires both va_start and va_end to be called from the
same function. On the other hand, vsnprintf and vsprintf leave the
va_list on an undefined state according to the standard, so a copy must
be created before a second call to these functions.
2020-10-14 08:27:19 +02:00
Xavier Del Campo Romero c862d84d0b Add dynstr_vprepend 2020-10-08 11:24:24 +02:00
Xavier Del Campo Romero 8bd1123857 Add dynstr_vappend 2020-10-06 09:20:57 +02:00
Xavier Del Campo Romero 134ebfa751 Call dynstr_init on dynstr_free 2020-09-03 14:43:02 +02:00
Xavier Del Campo Romero fe3c74983c dynstr_prepend(), fixed typo in comment 2020-08-03 23:47:18 +02:00
Xavier Del Campo Romero 2b01e38ca2 Various minor changes
- Removed trailing ';' from convenience macros.
- Convenience macros did not really need the ## __VA_ARGS__ extension.
Simply grouping all parameters into '...', while decreasing readability,
solves the portability issue.
- Added C99 check to dynstr.c.
2020-06-12 10:27:12 +02:00
Xavier Del Campo Romero 357d4f2c0f Avoid free() if no string is present 2020-03-25 10:48:54 +01:00
XaviDCR92 34643b8a8d Various changes and improvements
- Replaced int by specific, more meaningful error codes.
- C99 states realloc can be safely called using NULL pointers.
- New function dynstr_dup().
2020-03-21 13:14:48 +01:00
Xavi Del Campo 92409d275f Solved compiler error by adding scope block 2020-03-21 01:09:43 +01:00
Xavier Del Campo Romero 67ee01d77c Replaced unneeded calloc() by malloc() 2020-03-20 09:25:58 +01:00
Xavi Del Campo 73dd849484 First commit 2020-03-19 18:40:31 +01:00