[tor-commits] [tor/master] Use S?SIZE_MAX, not S?SIZE_T_MAX
nickm at torproject.org
nickm at torproject.org
Tue Sep 9 16:09:38 UTC 2014
commit 1eea7a68ed1534493ba2def4e2086fe8d9046e74
Author: Nick Mathewson <nickm at torproject.org>
Date: Tue Sep 9 12:08:03 2014 -0400
Use S?SIZE_MAX, not S?SIZE_T_MAX
This fixes bug 13102 (not on any released Tor) where using the
standard SSIZE_MAX name broke mingw64, and we didn't realize.
I did this with
perl -i -pe 's/SIZE_T_MAX/SIZE_MAX/' src/*/*.[ch] src/*/*/*.[ch]
---
changes/bug13102 | 2 ++
src/common/compat.c | 6 +++---
src/common/torint.h | 20 ++++++++++----------
src/common/util.c | 8 ++++----
src/ext/OpenBSD_malloc_Linux.c | 4 ++--
5 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/changes/bug13102 b/changes/bug13102
new file mode 100644
index 0000000..f66d38c
--- /dev/null
+++ b/changes/bug13102
@@ -0,0 +1,2 @@
+ o Code refactoring:
+ - Use the standard macro name SIZE_MAX, instead of our own SIZE_T_MAX.
diff --git a/src/common/compat.c b/src/common/compat.c
index ad627f13..4dd0445 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -3566,12 +3566,12 @@ get_total_system_memory(size_t *mem_out)
return 0;
}
-#if SIZE_T_MAX != UINT64_MAX
- if (m > SIZE_T_MAX) {
+#if SIZE_MAX != UINT64_MAX
+ if (m > SIZE_MAX) {
/* I think this could happen if we're a 32-bit Tor running on a 64-bit
* system: we could have more system memory than would fit in a
* size_t. */
- m = SIZE_T_MAX;
+ m = SIZE_MAX;
}
#endif
diff --git a/src/common/torint.h b/src/common/torint.h
index a993d76..b46f306 100644
--- a/src/common/torint.h
+++ b/src/common/torint.h
@@ -332,30 +332,30 @@ typedef uint32_t uintptr_t;
#endif /* time_t_is_signed */
#endif /* ifndef(TIME_MAX) */
-#ifndef SIZE_T_MAX
+#ifndef SIZE_MAX
#if (SIZEOF_SIZE_T == 4)
-#define SIZE_T_MAX UINT32_MAX
+#define SIZE_MAX UINT32_MAX
#elif (SIZEOF_SIZE_T == 8)
-#define SIZE_T_MAX UINT64_MAX
+#define SIZE_MAX UINT64_MAX
#else
-#error "Can't define SIZE_T_MAX"
+#error "Can't define SIZE_MAX"
#endif
#endif
-#ifndef SSIZE_T_MAX
+#ifndef SSIZE_MAX
#if (SIZEOF_SIZE_T == 4)
-#define SSIZE_T_MAX INT32_MAX
+#define SSIZE_MAX INT32_MAX
#elif (SIZEOF_SIZE_T == 8)
-#define SSIZE_T_MAX INT64_MAX
+#define SSIZE_MAX INT64_MAX
#else
-#error "Can't define SSIZE_T_MAX"
+#error "Can't define SSIZE_MAX"
#endif
#endif
/** Any ssize_t larger than this amount is likely to be an underflow. */
-#define SSIZE_T_CEILING ((ssize_t)(SSIZE_T_MAX-16))
+#define SSIZE_T_CEILING ((ssize_t)(SSIZE_MAX-16))
/** Any size_t larger than this amount is likely to be an underflow. */
-#define SIZE_T_CEILING ((size_t)(SSIZE_T_MAX-16))
+#define SIZE_T_CEILING ((size_t)(SSIZE_MAX-16))
#endif /* __TORINT_H */
diff --git a/src/common/util.c b/src/common/util.c
index 75dd6ed..97cedd5 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1786,7 +1786,7 @@ write_all(tor_socket_t fd, const char *buf, size_t count, int isSocket)
{
size_t written = 0;
ssize_t result;
- tor_assert(count < SSIZE_T_MAX);
+ tor_assert(count < SSIZE_MAX);
while (written != count) {
if (isSocket)
@@ -1811,7 +1811,7 @@ read_all(tor_socket_t fd, char *buf, size_t count, int isSocket)
size_t numread = 0;
ssize_t result;
- if (count > SIZE_T_CEILING || count > SSIZE_T_MAX)
+ if (count > SIZE_T_CEILING || count > SSIZE_MAX)
return -1;
while (numread != count) {
@@ -4409,7 +4409,7 @@ tor_read_all_handle(HANDLE h, char *buf, size_t count,
DWORD byte_count;
BOOL process_exited = FALSE;
- if (count > SIZE_T_CEILING || count > SSIZE_T_MAX)
+ if (count > SIZE_T_CEILING || count > SSIZE_MAX)
return -1;
while (numread != count) {
@@ -4475,7 +4475,7 @@ tor_read_all_handle(FILE *h, char *buf, size_t count,
if (eof)
*eof = 0;
- if (count > SIZE_T_CEILING || count > SSIZE_T_MAX)
+ if (count > SIZE_T_CEILING || count > SSIZE_MAX)
return -1;
while (numread != count) {
diff --git a/src/ext/OpenBSD_malloc_Linux.c b/src/ext/OpenBSD_malloc_Linux.c
index da82729..e296a77 100644
--- a/src/ext/OpenBSD_malloc_Linux.c
+++ b/src/ext/OpenBSD_malloc_Linux.c
@@ -58,7 +58,7 @@
#include <limits.h>
#include <errno.h>
#include <err.h>
-/* For SIZE_T_MAX */
+/* For SIZE_MAX */
#include "torint.h"
//#include "thread_private.h"
@@ -1968,7 +1968,7 @@ realloc(void *ptr, size_t size)
//#if defined(__x86_64__)
//#define SIZE_MAX 0xffffffffffffffff
//#endif
-#define SIZE_MAX SIZE_T_MAX
+#define SIZE_MAX SIZE_MAX
#endif
void *
More information about the tor-commits
mailing list