Fix these issues:
/home/smarchi/src/argpar/argpar/argpar.h:344:9: warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]
344 | _item = NULL; \
| ^
| ( )
argpar.c:525:34: warning: 'iter->tmp_buf.data' may be set to null if 'realloc' fails, which may result in a leak of the original buffer [bugprone-suspicious-realloc-usage]
525 | iter->tmp_buf.data = ARGPAR_REALLOC(iter->tmp_buf.data, char, iter->tmp_buf.size);
| ~~~~~~~~~~~~~~~~~~ ^
argpar.c:15:56: note: expanded from macro 'ARGPAR_REALLOC'
15 | #define ARGPAR_REALLOC(_ptr, _type, _nmemb) ((_type *) realloc(_ptr, (_nmemb) * sizeof(_type)))
| ^ ~~~~
Change-Id: I2e42059f8c4c744e10bdbc7c78b2628a53cd60d7
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
/* Isolate the option name */
while (long_opt_name_size > iter->tmp_buf.size - 1) {
/* Isolate the option name */
while (long_opt_name_size > iter->tmp_buf.size - 1) {
- iter->tmp_buf.size *= 2;
- iter->tmp_buf.data = ARGPAR_REALLOC(iter->tmp_buf.data, char, iter->tmp_buf.size);
- if (!iter->tmp_buf.data) {
+ const size_t new_size = iter->tmp_buf.size * 2;
+ char * const new_data = ARGPAR_REALLOC(iter->tmp_buf.data, char, new_size);
+
+ if (!new_data) {
ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
goto error;
}
ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
goto error;
}
+
+ iter->tmp_buf.size = new_size;
+ iter->tmp_buf.data = new_data;
}
memcpy(iter->tmp_buf.data, long_opt_arg, long_opt_name_size);
}
memcpy(iter->tmp_buf.data, long_opt_arg, long_opt_name_size);
#define ARGPAR_ITEM_DESTROY_AND_RESET(_item) \
{ \
argpar_item_destroy(_item); \
#define ARGPAR_ITEM_DESTROY_AND_RESET(_item) \
{ \
argpar_item_destroy(_item); \