Permalink
Browse files

Merge pull request #29 from PerGraa/master

Fix issues #28 and #31
  • Loading branch information...
2 parents cce89e3 + e6d37ff commit e2a6a439951f96a1c1853f574d8f15e33bf50d56 @YasserAsmi committed on GitHub Nov 21, 2016
Showing with 21 additions and 3 deletions.
  1. +3 −0 example/jsonparse.cpp
  2. +18 −3 include/str.h
@@ -95,6 +95,7 @@ void testJsonSuite()
if (dir == NULL)
{
printf("Error: failed to open jsontest directory\n");
+ closedir(dir);
return;
}
@@ -122,6 +123,8 @@ void testJsonSuite()
}
}
}
+
+ closedir(dir);
}
#endif
View
@@ -534,8 +534,13 @@ class StrBld
const char* c_str()
{
char* buf = (char*)mBuf.ptr();
- // Lazy null termination
- buf[mLen] = '\0';
+ if(buf)
+ {
+ // Lazy null termination
+ buf[mLen] = '\0';
+ }
+ // May return buffer without zero termination,
+ // but better than writing to null pointer.
return buf;
}
std::string toString()
@@ -554,7 +559,17 @@ class StrBld
inline int compare(const char* s)
{
- return strcmp(c_str(), s);
+ const char* cp = c_str();
+
+ if (cp)
+ {
+ return strcmp(cp, s);
+ }
+ else
+ {
+ // cp is null, fallback to direct comparison
+ return cp != s;
+ }
}
inline bool equals(const char* s)
{

0 comments on commit e2a6a43

Please sign in to comment.