[PATCH] D48271: [llvm-readobj] Fix printing format

Paul Semel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 11 01:36:18 PDT 2018


paulsemel added inline comments.


================
Comment at: tools/llvm-readobj/ELFDumper.cpp:3280
+  for (char C : S)
+    W << (isprint(C) ? C : '.');
+}
----------------
amccarth wrote:
> The behavior of isprint is undefined if the value is not representable as an unsigned char.  Since char on Windows is signed (by default), this means that some bytes could be negative, which is not representable and an unsigned char.
> 
> I think the safest thing to do is to cast `C` to `unsigned char`.
Hmm I'm perplex.. Doesn't `isprint` take an `int` as parameter ? I mean, if it takes an int in parameter, I don't understand why it could lead to undefined behavior if we give it a negative number...
Can you elaborate on this one, I'm really curious to learn where is the problem :)


Repository:
  rL LLVM

https://reviews.llvm.org/D48271





More information about the llvm-commits mailing list