1
0
mirror of https://github.com/fumiama/base16384.git synced 2026-06-13 00:00:23 +08:00

fix(test): buffer overflow & adapt to windows

This commit is contained in:
源文雨
2024-04-05 16:05:30 +08:00
parent 29e4019ed1
commit b9e02241bd
3 changed files with 11 additions and 11 deletions

View File

@@ -57,7 +57,7 @@
#define htobe64(x) htonll(x) #define htobe64(x) htonll(x)
#endif #endif
#endif #endif
#ifdef _MSC_VER #ifdef _WIN32
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
#define be16toh(x) (x) #define be16toh(x) (x)
#define be32toh(x) (x) #define be32toh(x) (x)
@@ -70,15 +70,15 @@
#define htobe64(x) (x) #define htobe64(x) (x)
#endif #endif
#else #else
#define be16toh(x) _bitswap_ushort(x) #define be16toh(x) _byteswap_ushort(x)
#define be32toh(x) _bitswap_ulong(x) #define be32toh(x) _byteswap_ulong(x)
#ifdef IS_64BIT_PROCESSOR #ifdef IS_64BIT_PROCESSOR
#define be64toh(x) _bitswap_uint64(x) #define be64toh(x) _byteswap_uint64(x)
#endif #endif
#define htobe16(x) _bitswap_ushort(x) #define htobe16(x) _byteswap_ushort(x)
#define htobe32(x) _bitswap_ulong(x) #define htobe32(x) _byteswap_ulong(x)
#ifdef IS_64BIT_PROCESSOR #ifdef IS_64BIT_PROCESSOR
#define htobe64(x) _bitswap_uint64(x) #define htobe64(x) _byteswap_uint64(x)
#endif #endif
#endif #endif
#endif #endif

View File

@@ -44,12 +44,12 @@ char decbuf[BASE16384_DECBUFSZ];
char tstbuf[BASE16384_ENCBUFSZ]; char tstbuf[BASE16384_ENCBUFSZ];
#define init_input_file() \ #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(); \ *(int*)(&encbuf[i]) = rand(); \
} \ } \
fp = fopen(TEST_INPUT_FILENAME, "wb"); \ fp = fopen(TEST_INPUT_FILENAME, "wb"); \
ok(!fp, "fopen"); \ 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"); \ ok(fclose(fp), "fclose"); \
fputs("input file created.\n", stderr); fputs("input file created.\n", stderr);

View File

@@ -44,12 +44,12 @@ char decbuf[BASE16384_DECBUFSZ];
char tstbuf[BASE16384_ENCBUFSZ]; char tstbuf[BASE16384_ENCBUFSZ];
#define init_input_file() \ #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(); \ *(int*)(&encbuf[i]) = rand(); \
} \ } \
fp = fopen(TEST_INPUT_FILENAME, "wb"); \ fp = fopen(TEST_INPUT_FILENAME, "wb"); \
ok(!fp, "fopen"); \ 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"); \ ok(fclose(fp), "fclose"); \
fputs("input file created.\n", stderr); fputs("input file created.\n", stderr);