Răsfoiți Sursa

avoid 64bit warnings when using pointers as entropy for temp names

Rich Felker 13 ani în urmă
părinte
comite
0e1762539c
2 a modificat fișierele cu 4 adăugiri și 2 ștergeri
  1. 2 1
      src/stdio/tempnam.c
  2. 2 1
      src/stdio/tmpnam.c

+ 2 - 1
src/stdio/tempnam.c

@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <unistd.h>
 #include <time.h>
 #include "libc.h"
@@ -30,7 +31,7 @@ char *tempnam(const char *dir, const char *pfx)
 
 	do {
 		clock_gettime(CLOCK_REALTIME, &ts);
-		n = ts.tv_nsec ^ (unsigned)&s ^ (unsigned)s;
+		n = ts.tv_nsec ^ (uintptr_t)&s ^ (uintptr_t)s;
 		snprintf(s, l, "%s/%s-%d-%d-%x", dir, pfx, pid, a_fetch_add(&index, 1), n);
 	} while (!access(s, F_OK) && try++<MAXTRIES);
 	if (try>=MAXTRIES) {

+ 2 - 1
src/stdio/tmpnam.c

@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <unistd.h>
 #include <time.h>
 #include "libc.h"
@@ -23,7 +24,7 @@ char *tmpnam(char *s)
 
 	do {
 		__syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts, 0);
-		n = ts.tv_nsec ^ (unsigned)&s ^ (unsigned)s;
+		n = ts.tv_nsec ^ (uintptr_t)&s ^ (uintptr_t)s;
 		snprintf(s, L_tmpnam, "/tmp/t%x-%x", a_fetch_add(&index, 1), n);
 	} while (!__syscall(SYS_access, s, F_OK) && try++<MAXTRIES);
 	return try>=MAXTRIES ? 0 : s;