Skip to content

Commit

Permalink
nlsfuncs: work around an overzealous GCC warning
Browse files Browse the repository at this point in the history
GCC 13 (and maybe 12, too), warn about pointers used after `free()`.

In `nlsfuncs.cc`, they are used on purpose, though, in
`rebase_locale_buf()`, to adjust pointers that were invalidated because
of a `realloc()` (not a `free()`, actually).

So let's shush GCC about those instances.

However, we must be careful only to do that with GCC >= 12 because older
versions would complain about an unknown warning...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Nov 25, 2023
1 parent 52b92eb commit 09fa455
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions winsup/cygwin/nlsfuncs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,13 @@ rebase_locale_buf (const void *ptrv, const void *ptrvend, const char *newbase,
{
const char **ptrsend = (const char **) ptrvend;
for (const char **ptrs = (const char **) ptrv; ptrs < ptrsend; ++ptrs)
#pragma GCC diagnostic push
#if __GNUC__ >= 12
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
if (*ptrs >= oldbase && *ptrs < oldend)
*ptrs += newbase - oldbase;
#pragma GCC diagnostic pop
}

static wchar_t *
Expand Down Expand Up @@ -613,10 +618,15 @@ __set_lc_time_from_win (const char *name,
era = NULL;
else
{
#pragma GCC diagnostic push
#if __GNUC__ >= 12
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
if (tmp != new_lc_time_buf)
rebase_locale_buf (_time_locale, _time_locale + 1, tmp,
new_lc_time_buf, lc_time_ptr);
lc_time_ptr = tmp + (lc_time_ptr - new_lc_time_buf);
#pragma GCC diagnostic pop
new_lc_time_buf = tmp;
lc_time_end = new_lc_time_buf + len;
}
Expand Down Expand Up @@ -675,9 +685,14 @@ __set_lc_time_from_win (const char *name,
free (new_lc_time_buf);
return -1;
}
#pragma GCC diagnostic push
#if __GNUC__ >= 12
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
if (tmp != new_lc_time_buf)
rebase_locale_buf (_time_locale, _time_locale + 1, tmp,
new_lc_time_buf, lc_time_ptr);
#pragma GCC diagnostic pop
*lc_time_buf = tmp;
return 1;
}
Expand Down Expand Up @@ -747,9 +762,14 @@ __set_lc_ctype_from_win (const char *name,
free (new_lc_ctype_buf);
return -1;
}
#pragma GCC diagnostic push
#if __GNUC__ >= 12
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
if (tmp != new_lc_ctype_buf)
rebase_locale_buf (_ctype_locale, _ctype_locale + 1, tmp,
new_lc_ctype_buf, lc_ctype_ptr);
#pragma GCC diagnostic pop
*lc_ctype_buf = tmp;
return 1;
}
Expand Down Expand Up @@ -822,9 +842,14 @@ __set_lc_numeric_from_win (const char *name,
free (new_lc_numeric_buf);
return -1;
}
#pragma GCC diagnostic push
#if __GNUC__ >= 12
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
if (tmp != new_lc_numeric_buf)
rebase_locale_buf (_numeric_locale, _numeric_locale + 1, tmp,
new_lc_numeric_buf, lc_numeric_ptr);
#pragma GCC diagnostic pop
*lc_numeric_buf = tmp;
return 1;
}
Expand Down Expand Up @@ -959,9 +984,14 @@ __set_lc_monetary_from_win (const char *name,
free (new_lc_monetary_buf);
return -1;
}
#pragma GCC diagnostic push
#if __GNUC__ >= 12
#pragma GCC diagnostic ignored "-Wuse-after-free"
#endif
if (tmp != new_lc_monetary_buf)
rebase_locale_buf (_monetary_locale, _monetary_locale + 1, tmp,
new_lc_monetary_buf, lc_monetary_ptr);
#pragma GCC diagnostic pop
*lc_monetary_buf = tmp;
return 1;
}
Expand Down

0 comments on commit 09fa455

Please sign in to comment.