diff --git a/src/files.c b/src/files.c index 28ac17d..6689118 100644 --- a/src/files.c +++ b/src/files.c @@ -57,12 +57,11 @@ ksrbuffer* read_file(FILE *file) // getting back to the beginning of the file. fseek(file, 0, SEEK_SET); - // allocating a buffer corresponding to the file size, plus the end of string char. - ksrbuffer *buffer = ksrbuffer_new(filesize + 1); + // allocating a buffer corresponding to the file size. + ksrbuffer *buffer = ksrbuffer_new(filesize); // reading the file into the buffer. fread(buffer->bytes, 1, buffer->length, file); - buffer->bytes[buffer->length - 1] = 0; // 0-terminated string. return buffer; // returning allocated buffer. } diff --git a/tests/ksrfiles.c b/tests/ksrfiles.c index 633a341..6dfca09 100644 --- a/tests/ksrfiles.c +++ b/tests/ksrfiles.c @@ -11,13 +11,12 @@ int main(void) write_file("ksrtesttesttmp/tmp/test.tmp", buffer); // try to read the previously written file, and checking that the buffer has been read properly. - ksrbuffer *read_buffer = read_file_from_path("test.tmp"); - assert(read_buffer->length == 13); + ksrbuffer *read_buffer = read_file_from_path("ksrtesttesttmp/tmp/test.tmp"); + assert(read_buffer->length == 12); assert(read_buffer->bytes[0] == 'H'); assert(read_buffer->bytes[3] == 'l'); assert(read_buffer->bytes[7] == 'o'); assert(read_buffer->bytes[11] == '!'); - assert(read_buffer->bytes[12] == 0); // delete test directory. system("rm -Rf ksrtesttesttmp");