aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sysdep.c54
1 files changed, 21 insertions, 33 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 635443cfe66..7f64a3b9fbc 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -99,15 +99,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
99#include "process.h" 99#include "process.h"
100#include "cm.h" 100#include "cm.h"
101 101
102#ifdef HAVE_GNUTLS
103# include <gnutls/gnutls.h>
104#endif
105#if 0x020c00 <= GNUTLS_VERSION_NUMBER
106# include <gnutls/crypto.h>
107#else
108# define gnutls_rnd(level, data, len) (-1)
109#endif
110
111#ifdef WINDOWSNT 102#ifdef WINDOWSNT
112#include <direct.h> 103#include <direct.h>
113/* In process.h which conflicts with the local copy. */ 104/* In process.h which conflicts with the local copy. */
@@ -2105,25 +2096,22 @@ void
2105init_random (void) 2096init_random (void)
2106{ 2097{
2107 random_seed v; 2098 random_seed v;
2108 if (gnutls_rnd (GNUTLS_RND_NONCE, &v, sizeof v) != 0) 2099 bool success = false;
2109 {
2110 bool success = false;
2111#ifndef WINDOWSNT 2100#ifndef WINDOWSNT
2112 int fd = emacs_open ("/dev/urandom", O_RDONLY | O_BINARY, 0); 2101 int fd = emacs_open ("/dev/urandom", O_RDONLY | O_BINARY, 0);
2113 if (0 <= fd) 2102 if (fd >= 0)
2114 { 2103 {
2115 success = emacs_read (fd, &v, sizeof v) == sizeof v; 2104 success = emacs_read (fd, &v, sizeof v) == sizeof v;
2116 emacs_close (fd); 2105 emacs_close (fd);
2117 } 2106 }
2118#else 2107#else
2119 success = w32_init_random (&v, sizeof v) == 0; 2108 success = w32_init_random (&v, sizeof v) == 0;
2120#endif 2109#endif
2121 if (! success) 2110 if (! success)
2122 { 2111 {
2123 /* Fall back to current time value + PID. */ 2112 /* Fall back to current time value + PID. */
2124 struct timespec t = current_timespec (); 2113 struct timespec t = current_timespec ();
2125 v = getpid () ^ t.tv_sec ^ t.tv_nsec; 2114 v = getpid () ^ t.tv_sec ^ t.tv_nsec;
2126 }
2127 } 2115 }
2128 set_random_seed (v); 2116 set_random_seed (v);
2129} 2117}
@@ -2175,7 +2163,7 @@ snprintf (char *buf, size_t bufsize, char const *format, ...)
2175 xfree (b); 2163 xfree (b);
2176 } 2164 }
2177 2165
2178 if (INT_MAX < nbytes) 2166 if (nbytes > INT_MAX)
2179 { 2167 {
2180#ifdef EOVERFLOW 2168#ifdef EOVERFLOW
2181 errno = EOVERFLOW; 2169 errno = EOVERFLOW;
@@ -2233,7 +2221,7 @@ emacs_backtrace (int backtrace_limit)
2233 { 2221 {
2234 emacs_write (STDERR_FILENO, "\nBacktrace:\n", 12); 2222 emacs_write (STDERR_FILENO, "\nBacktrace:\n", 12);
2235 backtrace_symbols_fd (buffer, npointers, STDERR_FILENO); 2223 backtrace_symbols_fd (buffer, npointers, STDERR_FILENO);
2236 if (bounded_limit < npointers) 2224 if (npointers > bounded_limit)
2237 emacs_write (STDERR_FILENO, "...\n", 4); 2225 emacs_write (STDERR_FILENO, "...\n", 4);
2238 } 2226 }
2239} 2227}
@@ -2262,7 +2250,7 @@ emacs_open (const char *file, int oflags, int mode)
2262 oflags |= O_CLOEXEC; 2250 oflags |= O_CLOEXEC;
2263 while ((fd = open (file, oflags, mode)) < 0 && errno == EINTR) 2251 while ((fd = open (file, oflags, mode)) < 0 && errno == EINTR)
2264 QUIT; 2252 QUIT;
2265 if (! O_CLOEXEC && 0 <= fd) 2253 if (! O_CLOEXEC && fd >= 0)
2266 fcntl (fd, F_SETFD, FD_CLOEXEC); 2254 fcntl (fd, F_SETFD, FD_CLOEXEC);
2267 return fd; 2255 return fd;
2268} 2256}
@@ -2829,9 +2817,9 @@ time_from_jiffies (unsigned long long tval, long hz)
2829 unsigned long long frac = tval % hz; 2817 unsigned long long frac = tval % hz;
2830 int ns; 2818 int ns;
2831 2819
2832 if (TYPE_MAXIMUM (time_t) < s) 2820 if (s > TYPE_MAXIMUM (time_t))
2833 time_overflow (); 2821 time_overflow ();
2834 if (LONG_MAX - 1 <= ULLONG_MAX / TIMESPEC_RESOLUTION 2822 if (ULLONG_MAX / TIMESPEC_RESOLUTION >= LONG_MAX - 1
2835 || frac <= ULLONG_MAX / TIMESPEC_RESOLUTION) 2823 || frac <= ULLONG_MAX / TIMESPEC_RESOLUTION)
2836 ns = frac * TIMESPEC_RESOLUTION / hz; 2824 ns = frac * TIMESPEC_RESOLUTION / hz;
2837 else 2825 else
@@ -3049,7 +3037,7 @@ system_process_attributes (Lisp_Object pid)
3049 record_unwind_protect_int (close_file_unwind, fd); 3037 record_unwind_protect_int (close_file_unwind, fd);
3050 nread = emacs_read (fd, procbuf, sizeof procbuf - 1); 3038 nread = emacs_read (fd, procbuf, sizeof procbuf - 1);
3051 } 3039 }
3052 if (0 < nread) 3040 if (nread > 0)
3053 { 3041 {
3054 procbuf[nread] = '\0'; 3042 procbuf[nread] = '\0';
3055 p = procbuf; 3043 p = procbuf;
@@ -3176,12 +3164,12 @@ system_process_attributes (Lisp_Object pid)
3176 if (nread) 3164 if (nread)
3177 { 3165 {
3178 /* We don't want trailing null characters. */ 3166 /* We don't want trailing null characters. */
3179 for (p = cmdline + nread; cmdline < p && !p[-1]; p--) 3167 for (p = cmdline + nread; p > cmdline && !p[-1]; p--)
3180 continue; 3168 continue;
3181 3169
3182 /* Escape-quote whitespace and backslashes. */ 3170 /* Escape-quote whitespace and backslashes. */
3183 q = cmdline + cmdline_size; 3171 q = cmdline + cmdline_size;
3184 while (cmdline < p) 3172 while (p > cmdline)
3185 { 3173 {
3186 char c = *--p; 3174 char c = *--p;
3187 *--q = c ? c : ' '; 3175 *--q = c ? c : ' ';