mirror of
https://github.com/facebook/zstd.git
synced 2025-07-29 11:21:22 +03:00
visual studio fix
This commit is contained in:
@ -703,21 +703,34 @@ static size_t UTIL_processLines(char* buffer, size_t bufferSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create an array of pointers to the lines in a buffer */
|
/* Create an array of pointers to the lines in a buffer */
|
||||||
static const char**
|
static const char** UTIL_createLinePointers(char* buffer, size_t numLines, size_t bufferSize)
|
||||||
UTIL_createLinePointers(char* buffer, size_t numLines, size_t bufferSize)
|
|
||||||
{
|
{
|
||||||
size_t lineIndex = 0;
|
size_t lineIndex = 0;
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
const char** linePointers = (const char**)malloc(numLines * sizeof(*linePointers));
|
void* const bufferPtrs = malloc(numLines * sizeof(const char**));
|
||||||
if (linePointers == NULL) return NULL;
|
const char** const linePointers = (const char**)bufferPtrs;
|
||||||
|
if (bufferPtrs == NULL) return NULL;
|
||||||
|
|
||||||
while (lineIndex < numLines && pos < bufferSize) {
|
while (lineIndex < numLines && pos < bufferSize) {
|
||||||
linePointers[lineIndex++] = buffer + pos;
|
size_t len = 0;
|
||||||
pos += strlen(buffer + pos) + 1; /* +1 for the finishing `\0` */
|
linePointers[lineIndex++] = buffer+pos;
|
||||||
|
|
||||||
|
/* Find the next null terminator, being careful not to go past the buffer */
|
||||||
|
while ((pos + len < bufferSize) && buffer[pos + len] != '\0') {
|
||||||
|
len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(pos <= bufferSize);
|
/* Move past this string and its null terminator */
|
||||||
assert(lineIndex == numLines);
|
pos += len;
|
||||||
|
if (pos < bufferSize) pos++; /* Skip the null terminator if we're not at buffer end */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Verify we processed the expected number of lines */
|
||||||
|
if (lineIndex != numLines) {
|
||||||
|
/* Something went wrong - we didn't find as many lines as expected */
|
||||||
|
free(bufferPtrs);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return linePointers;
|
return linePointers;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user