This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] defs.h: Define GDB_DEFAULT_TARGET_[WIDE_]CHARSET for Cygwin and MingW builds
On Mar 3 11:41, Corinna Vinschen wrote:
> However, there's a problem in GDB which spoils the effort a bit.
>
> When GDB is started, setlocale() is called from captured_main().
> Afterwards, _initialize_charset() and, in turn, nl_langinfo() is
> called, and the pointer returned by nl_langinfo(CODESET) is
> stored as the name of the codeset.
> So the codeset name is not copied into a safe storage area here,
> just the pointer is memorized.
>
> Later, while captured_main() is still initializing GDB, the interp_set()
> function is called, which calls tui_init(), which in turn initializes
> readline. Readline calls setlocale(). Oops. The old pointer to
> nl_langinfo(CODESET) might not be valid anymore afterwards.
>
> See the Linux manpage for nl_langinfo:
>
> RETURN VALUE
> [...]
> This pointer may point to static data that may be overwritten on the
> next call to nl_langinfo() or setlocale(3).
>
> So, does anything speak against copying the codeset name into some
> local storage, rather than just storing the pointer returned by
> nl_langinfo?
Accidentally omitted from my former mail:
Since nl_langinfo is called only once here anyway, a simple
auto_host_charset_name = strdup (nl_langinfo (CODESET));
would do.
Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat