diff --git a/src/cborparser.c b/src/cborparser.c index 74d91a30..45ae23fb 100644 --- a/src/cborparser.c +++ b/src/cborparser.c @@ -1211,7 +1211,7 @@ static CborError iterate_string_chunks(const CborValue *value, char *buffer, siz return CborErrorDataTooLarge; if (*result && *buflen >= newTotal) - *result = !!func(buffer + total, (const uint8_t *)ptr, chunkLen); + *result = !!func(buffer == NULL ? buffer : buffer + total, (const uint8_t *)ptr, chunkLen); else *result = false; @@ -1221,7 +1221,7 @@ static CborError iterate_string_chunks(const CborValue *value, char *buffer, siz /* is there enough room for the ending NUL byte? */ if (*result && *buflen > total) { uint8_t nul[] = { 0 }; - *result = !!func(buffer + total, nul, 1); + *result = !!func(buffer == NULL ? buffer : buffer + total, nul, 1); } *buflen = total; return _cbor_value_finish_string_iteration(next);