fix some errors that happen when they shouldnt
This commit is contained in:
@@ -64,11 +64,13 @@ ResultType(int64_t, objectPtr) impl_read(int64_t* args, CometVM* vm) {
|
||||
}
|
||||
|
||||
size_t bytesRead = fread(content, amountToRead, 1, f);
|
||||
if (bytesRead != amountToRead) {
|
||||
if (bytesRead < amountToRead) {
|
||||
if (ferror(f)) {
|
||||
char* buffer = malloc(128);
|
||||
snprintf(buffer, 128, "Error while reading file: %s", strerror(errno));
|
||||
return cometError(vm, "IOFail", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// serialize string
|
||||
return Success(int64_t, objectPtr, cometSerializeString(content));
|
||||
@@ -88,9 +90,13 @@ ResultType(int64_t, objectPtr) impl_readLine(int64_t* args, CometVM* vm) {
|
||||
ssize_t read = getline(&line, &len, f);
|
||||
|
||||
if (read == -1) {
|
||||
if (ferror(f)) {
|
||||
char* buffer = malloc(128);
|
||||
snprintf(buffer, 128, "Error while reading line: %s", strerror(errno));
|
||||
return cometError(vm, "IOFail", buffer);
|
||||
} else {
|
||||
return Success(int64_t, objectPtr, cometSerializeString(""));
|
||||
}
|
||||
}
|
||||
|
||||
if (read > 0 && line[read - 1] == '\n') {
|
||||
|
||||
Reference in New Issue
Block a user