fafc064148fba3ad1efdb726b3ac3fdd0784d4e1 angie Mon Jan 4 18:02:21 2021 -0800 When a file has a single line of content with no newline, return the content instead of NULL. diff --git src/lib/udc.c src/lib/udc.c index 6322bbd..c1071f9 100644 --- src/lib/udc.c +++ src/lib/udc.c @@ -1797,31 +1797,36 @@ /* See if need to expand buffer, which is initially on stack, but if it gets big goes into * heap. */ if (i >= bufSize) { int newBufSize = bufSize*2; char *newBuf = needLargeMem(newBufSize); memcpy(newBuf, buf, bufSize); freeMem(longBuf); buf = longBuf = newBuf; bufSize = newBufSize; } char c; bits64 sizeRead = udcRead(file, &c, 1); if (sizeRead == 0) + { + // EOF before newline: return NULL for empty string + if (i == 0) return NULL; + break; + } buf[i] = c; if (c == '\n') { buf[i] = 0; break; } } char *retString = cloneString(buf); freeMem(longBuf); return retString; } char *udcReadStringAndZero(struct udcFile *file) /* Read in zero terminated string from file. Do a freeMem of result when done. */ {