mirror of https://github.com/flysand7/ciabatta.git
Fix integer overflow on SetFilePointer
This commit is contained in:
parent
1b19084f16
commit
c8bee66744
|
@ -594,8 +594,7 @@ int fgetpos(FILE *restrict stream, fpos_t *restrict pos) {
|
||||||
int fseek(FILE *stream, long int offset, int whence) {
|
int fseek(FILE *stream, long int offset, int whence) {
|
||||||
// Note(bumbread): the SEEK_SET, SEEK_CUR and SEEK_END are defined to match
|
// Note(bumbread): the SEEK_SET, SEEK_CUR and SEEK_END are defined to match
|
||||||
// the Windows constants, so no conversion is requierd between them.
|
// the Windows constants, so no conversion is requierd between them.
|
||||||
LONG pos_hi = 0;
|
DWORD pos_lo = SetFilePointer(stream->handle, offset, NULL, whence);
|
||||||
DWORD pos_lo = SetFilePointer(stream->handle, offset, &pos_hi, whence);
|
|
||||||
if(pos_lo == INVALID_SET_FILE_POINTER) {
|
if(pos_lo == INVALID_SET_FILE_POINTER) {
|
||||||
return -1L;
|
return -1L;
|
||||||
}
|
}
|
||||||
|
@ -603,9 +602,8 @@ int fseek(FILE *stream, long int offset, int whence) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int fsetpos(FILE *stream, const fpos_t *pos) {
|
int fsetpos(FILE *stream, const fpos_t *pos) {
|
||||||
LONG pos_hi = pos->offset >> 32;
|
|
||||||
LONG pos_lo = (LONG)(pos->offset & 0xffffffff);
|
LONG pos_lo = (LONG)(pos->offset & 0xffffffff);
|
||||||
DWORD status = SetFilePointer(stream->handle, pos_lo, &pos_hi, FILE_BEGIN);
|
DWORD status = SetFilePointer(stream->handle, pos_lo, NULL, FILE_BEGIN);
|
||||||
if(status == INVALID_SET_FILE_POINTER) {
|
if(status == INVALID_SET_FILE_POINTER) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
2
test.bat
2
test.bat
|
@ -1,3 +1,5 @@
|
||||||
|
|
||||||
clang -g test\%1.c -I include utf8.obj -nostdlib -mfma -lciabatta.lib
|
clang -g test\%1.c -I include utf8.obj -nostdlib -mfma -lciabatta.lib
|
||||||
|
if %errorlevel%==0 (
|
||||||
"./a.exe"
|
"./a.exe"
|
||||||
|
)
|
||||||
|
|
|
@ -198,6 +198,7 @@ struct Test {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void print_test_results(Test_Feature *features_head) {
|
static void print_test_results(Test_Feature *features_head) {
|
||||||
|
prints(":: Printing test results\n");
|
||||||
int total_test_count = 0;
|
int total_test_count = 0;
|
||||||
int total_success_count = 0;
|
int total_success_count = 0;
|
||||||
for(Test_Feature *feature = features_head; feature != NULL; feature = feature->next) {
|
for(Test_Feature *feature = features_head; feature != NULL; feature = feature->next) {
|
||||||
|
@ -245,6 +246,7 @@ Test_Feature *current_feature = NULL;
|
||||||
|
|
||||||
#define FEATURE_START__(NAME, NUMBER) \
|
#define FEATURE_START__(NAME, NUMBER) \
|
||||||
{ \
|
{ \
|
||||||
|
print_fmt(":: Running tests for %s\n", NAME); \
|
||||||
Test_Feature *feature = mem_alloc(sizeof(Test_Feature)); \
|
Test_Feature *feature = mem_alloc(sizeof(Test_Feature)); \
|
||||||
feature->next = current_feature; \
|
feature->next = current_feature; \
|
||||||
current_feature = feature; \
|
current_feature = feature; \
|
||||||
|
@ -577,6 +579,7 @@ int main(int argc, char **argv) {
|
||||||
TEST(file != NULL, "Created file is NULL");
|
TEST(file != NULL, "Created file is NULL");
|
||||||
TEST(fwrite(numbers, sizeof(int), 10, file) == 10, "fwrite didn't write all 10 objects");
|
TEST(fwrite(numbers, sizeof(int), 10, file) == 10, "fwrite didn't write all 10 objects");
|
||||||
TEST(fseek(file, 4*sizeof(int), SEEK_SET) == 0, "fseek couldn't seek to offset 4");
|
TEST(fseek(file, 4*sizeof(int), SEEK_SET) == 0, "fseek couldn't seek to offset 4");
|
||||||
|
// TEST(fflush(file) == 0, "fflush failed");
|
||||||
int num;
|
int num;
|
||||||
TEST(fread(&num, sizeof(int), 1, file) == 1, "fread didn't read the int");
|
TEST(fread(&num, sizeof(int), 1, file) == 1, "fread didn't read the int");
|
||||||
TEST(num == 4, "Wrong value read at offset 4");
|
TEST(num == 4, "Wrong value read at offset 4");
|
||||||
|
|
Loading…
Reference in New Issue