[PATCH] D37331: [ELF] Prevent crash with binary inputs with non-ascii file names

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 1 12:14:29 PDT 2017


ruiu added inline comments.


================
Comment at: ELF/InputFiles.cpp:934
   for (size_t I = 0; I < S.size(); ++I)
-    if (!isalnum(S[I]))
+    if (!isalnum(static_cast<unsigned char>(S[I])))
       S[I] = '_';
----------------
jhenderson wrote:
> ruiu wrote:
> > isalnum might be locale-aware, so it is probably not safe to use here in the first place. Doing it manually (i.e. `'a' <= S[I] <= 'z' || 'A' <= S[I] <= 'Z' || '0' <= S[I] <= '0'` ) seems better.
> isalnum is locale aware, but as far as I can see, we never change the locale away from the default C locale, so do we need to worry about it?
Not all people are using their OSes in English/US UI, and I think if system's default locale is not C, isalpha could behave differently depending on the definition of "alphabet" in that system locale.


https://reviews.llvm.org/D37331





More information about the llvm-commits mailing list