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:
14
binary.h
14
binary.h
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user