tap: import some changes
[argpar.git] / argpar / argpar.c
index 67b77691cbe19784667e1c17013e686f74dc38a6..5c3d8faadfd2af5cb47acc121a8e30b8c4f85df3 100644 (file)
@@ -1,8 +1,7 @@
 /*
  * SPDX-License-Identifier: MIT
- *
- * Copyright (c) 2019-2021 Philippe Proulx <pproulx@efficios.com>
- * Copyright (c) 2020-2021 Simon Marchi <simon.marchi@efficios.com>
+ * SPDX-FileCopyrightText: 2019-2024 Philippe Proulx <pproulx@efficios.com>
+ * SPDX-FileCopyrightText: 2020-2024 Simon Marchi <simon.marchi@efficios.com>
  */
 
 #include <stdbool.h>
@@ -532,12 +531,16 @@ parse_long_opt(const char * const long_opt_arg, const char * const next_orig_arg
 
         /* 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;
             }
+
+            iter->tmp_buf.size = new_size;
+            iter->tmp_buf.data = new_data;
         }
 
         memcpy(iter->tmp_buf.data, long_opt_arg, long_opt_name_size);
This page took 0.03886 seconds and 4 git commands to generate.