mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-09 10:39:11 +08:00
Rewrite to avoid new use-after-free warnings about realloc(), seen with gcc 12, e.g.: > In function ‘void rebase_locale_buf(const void*, const void*, const char*, const char*, const char*)’, > inlined from ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’ at ../../../../src/winsup/cygwin/nlsfuncs.cc:705:25: > ../../../../src/winsup/cygwin/nlsfuncs.cc:338:24: error: pointer ‘new_lc_time_buf’ may be used after ‘void* realloc(void*, size_t)’ [-Werror=use-after-free] > 338 | *ptrs += newbase - oldbase; > | ~~~~~~~~^~~~~~~~~ > ../../../../src/winsup/cygwin/nlsfuncs.cc: In function ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’: > ../../../../src/winsup/cygwin/nlsfuncs.cc:699:44: note: call to ‘void* realloc(void*, size_t)’ here > 699 | char *tmp = (char *) realloc (new_lc_time_buf, len); Technically, it's UB to later refer to the realloced pointer (even just for offset computations, without deferencing it), so switch to using malloc() to create the resized copy. Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cygwin documentation is available on the net at https://cygwin.com You might especially be interested in https://cygwin.com/faq/faq.html#faq.programming.building-cygwin