From b9e02241bdd38fafb885e7de3ebbee928b1b132c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:05:30 +0800 Subject: [PATCH] fix(test): buffer overflow & adapt to windows --- binary.h | 14 +++++++------- test/file_test.c | 4 ++-- test/wrap_test.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/binary.h b/binary.h index 0a5f996..46c7039 100644 --- a/binary.h +++ b/binary.h @@ -57,7 +57,7 @@ #define htobe64(x) htonll(x) #endif #endif - #ifdef _MSC_VER + #ifdef _WIN32 #ifdef WORDS_BIGENDIAN #define be16toh(x) (x) #define be32toh(x) (x) @@ -70,15 +70,15 @@ #define htobe64(x) (x) #endif #else - #define be16toh(x) _bitswap_ushort(x) - #define be32toh(x) _bitswap_ulong(x) + #define be16toh(x) _byteswap_ushort(x) + #define be32toh(x) _byteswap_ulong(x) #ifdef IS_64BIT_PROCESSOR - #define be64toh(x) _bitswap_uint64(x) + #define be64toh(x) _byteswap_uint64(x) #endif - #define htobe16(x) _bitswap_ushort(x) - #define htobe32(x) _bitswap_ulong(x) + #define htobe16(x) _byteswap_ushort(x) + #define htobe32(x) _byteswap_ulong(x) #ifdef IS_64BIT_PROCESSOR - #define htobe64(x) _bitswap_uint64(x) + #define htobe64(x) _byteswap_uint64(x) #endif #endif #endif diff --git a/test/file_test.c b/test/file_test.c index b5ed8ed..0e69266 100644 --- a/test/file_test.c +++ b/test/file_test.c @@ -44,12 +44,12 @@ char decbuf[BASE16384_DECBUFSZ]; char tstbuf[BASE16384_ENCBUFSZ]; #define init_input_file() \ - for(i = 0; i < TEST_SIZE; i += sizeof(int)) { \ + for(i = 0; i < BASE16384_ENCBUFSZ; i += sizeof(int)) { \ *(int*)(&encbuf[i]) = rand(); \ } \ fp = fopen(TEST_INPUT_FILENAME, "wb"); \ ok(!fp, "fopen"); \ - ok(fwrite(encbuf, TEST_SIZE, 1, fp) != 1, "fwrite"); \ + ok(fwrite(encbuf, BASE16384_ENCBUFSZ, 1, fp) != 1, "fwrite"); \ ok(fclose(fp), "fclose"); \ fputs("input file created.\n", stderr); diff --git a/test/wrap_test.c b/test/wrap_test.c index 4d5df88..2e87067 100644 --- a/test/wrap_test.c +++ b/test/wrap_test.c @@ -44,12 +44,12 @@ char decbuf[BASE16384_DECBUFSZ]; char tstbuf[BASE16384_ENCBUFSZ]; #define init_input_file() \ - for(i = 0; i < TEST_SIZE; i += sizeof(int)) { \ + for(i = 0; i < BASE16384_ENCBUFSZ; i += sizeof(int)) { \ *(int*)(&encbuf[i]) = rand(); \ } \ fp = fopen(TEST_INPUT_FILENAME, "wb"); \ ok(!fp, "fopen"); \ - ok(fwrite(encbuf, TEST_SIZE, 1, fp) != 1, "fwrite"); \ + ok(fwrite(encbuf, BASE16384_ENCBUFSZ, 1, fp) != 1, "fwrite"); \ ok(fclose(fp), "fclose"); \ fputs("input file created.\n", stderr);