cuimiaomiao / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

Possibly a tiny bug in demangle.cc #175

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
If you compile glog with clang-3.4 with all diagnostics on, you'll get the 
following error:
../glog/src/demangle.cc:170:13: error: comparison between pointer and integer 
('const char *' and 'int')
    if (str == '\0') {
        ~~~ ^  ~~~~
../glog/src/demangle.cc:226:26: error: comparison between pointer and integer 
('const char *' and 'int')
  if (state->mangled_cur == '\0') {
      ~~~~~~~~~~~~~~~~~~ ^  ~~~~

I guess clang is actually finding a bug, and the following patch might be the 
fix:

diff --git a/glog/src/demangle.cc b/glog/src/demangle.cc
index 0daf308..4b7c160 100644
--- a/glog/src/demangle.cc
+++ b/glog/src/demangle.cc
@@ -167,7 +167,7 @@ static size_t StrLen(const char *str) {
 // Returns true if "str" has at least "n" characters remaining.
 static bool AtLeastNumCharsRemaining(const char *str, int n) {
   for (int i = 0; i < n; ++i) {
-    if (str == '\0') {
+    if (str[i] == '\0') {
       return false;
     }
   }
@@ -223,7 +223,7 @@ static bool ParseTwoCharToken(State *state, const char 
*two_char_token) {
 // Returns true and advances "mangled_cur" if we find any character in
 // "char_class" at "mangled_cur" position.
 static bool ParseCharClass(State *state, const char *char_class) {
-  if (state->mangled_cur == '\0') {
+  if (state->mangled_cur[0] == '\0') {
     return false;
   }
   const char *p = char_class;

Original issue reported on code.google.com by soheil....@gmail.com on 7 Nov 2013 at 12:28

GoogleCodeExporter commented 8 years ago
Fixed in r141.

Original comment by Huahang.Liu@gmail.com on 25 May 2014 at 4:10