fix some errors that happen when they shouldnt

This commit is contained in:
2026-06-25 07:56:52 +10:00
parent e59685413d
commit ec4d41edb5

View File

@@ -64,10 +64,12 @@ ResultType(int64_t, objectPtr) impl_read(int64_t* args, CometVM* vm) {
}
size_t bytesRead = fread(content, amountToRead, 1, f);
if (bytesRead != amountToRead) {
char* buffer = malloc(128);
snprintf(buffer, 128, "Error while reading file: %s", strerror(errno));
return cometError(vm, "IOFail", buffer);
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
@@ -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) {
char* buffer = malloc(128);
snprintf(buffer, 128, "Error while reading line: %s", strerror(errno));
return cometError(vm, "IOFail", buffer);
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') {