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); size_t bytesRead = fread(content, amountToRead, 1, f);
if (bytesRead != amountToRead) { if (bytesRead < amountToRead) {
char* buffer = malloc(128); if (ferror(f)) {
snprintf(buffer, 128, "Error while reading file: %s", strerror(errno)); char* buffer = malloc(128);
return cometError(vm, "IOFail", buffer); snprintf(buffer, 128, "Error while reading file: %s", strerror(errno));
return cometError(vm, "IOFail", buffer);
}
} }
// serialize string // serialize string
@@ -88,9 +90,13 @@ ResultType(int64_t, objectPtr) impl_readLine(int64_t* args, CometVM* vm) {
ssize_t read = getline(&line, &len, f); ssize_t read = getline(&line, &len, f);
if (read == -1) { if (read == -1) {
char* buffer = malloc(128); if (ferror(f)) {
snprintf(buffer, 128, "Error while reading line: %s", strerror(errno)); char* buffer = malloc(128);
return cometError(vm, "IOFail", buffer); 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') { if (read > 0 && line[read - 1] == '\n') {