Permalink
Browse files

Made memchr use safer

  • Loading branch information...
1 parent 93c9c22 commit 0e073756db1ac4f99f577760d876f906d09ecfab Micah N Gorrell committed Dec 8, 2016
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/wjreader/wjreader.c
@@ -554,6 +554,7 @@ EXPORT size_t WJRFileCallback(char *buffer, size_t length, size_t seen, void *da
EXPORT size_t WJRMemCallback(char *buffer, size_t length, size_t seen, void *userdata)
{
char *json = (char *) userdata;
+ char *end;
size_t len;
if (!json) {
@@ -563,8 +564,12 @@ EXPORT size_t WJRMemCallback(char *buffer, size_t length, size_t seen, void *use
#if 0
len = strlen(json);
#else
- len = ((char *)memchr(json + seen, '\0', length + 1)) - json;
- // DebugAssert(len == strlen(json));
+ end = memchr(json + seen, '\0', length + 1);
+ if (end) {
+ len = end - json;
+ } else {
+ len = length;
+ }
#endif
if (len <= seen) {

0 comments on commit 0e07375

Please sign in to comment.