[Mesa-dev] [PATCH 24/24] gallium/aux/os: Fix warning/handle failure to read from /proc/self/cmdline
Gert Wollny
gert.wollny at collabora.com
Mon Jun 11 09:36:27 UTC 2018
Handle the failure to read from /proc/self/cmdline by printing an error
message and fix the -Wsign-compare warning:
In file included from ./util/u_memory.h:39:0,
from os/os_process.c:31:
os/os_process.c: In function 'os_get_command_line':
os/os_process.c:140:16: warning: comparison between signed and unsigned
integer expressions [-Wsign-compare]
assert(n < size);
^
./util/u_debug.h:189:30: note: in definition of macro 'debug_assert'
#define debug_assert(expr) ((expr) ? (void)0 :
_debug_assert_fail(#expr,
__FILE__, __LINE__, __FUNCTION__))
^~~~
os/os_process.c:140:7: note: in expansion of macro 'assert'
assert(n < size);
^~~~~~
gallium/aux/os/ squash
v2: - simplify patch (Emil Velikov)
- print error message only when compiled in debug mode
Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
---
src/gallium/auxiliary/os/os_process.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/gallium/auxiliary/os/os_process.c b/src/gallium/auxiliary/os/os_process.c
index 035bd228e7..ed03b81f85 100644
--- a/src/gallium/auxiliary/os/os_process.c
+++ b/src/gallium/auxiliary/os/os_process.c
@@ -29,6 +29,7 @@
#include "pipe/p_config.h"
#include "os/os_process.h"
#include "util/u_memory.h"
+#include <strings.h>
#if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
# include <windows.h>
@@ -135,9 +136,18 @@ os_get_command_line(char *cmdline, size_t size)
#elif defined(PIPE_OS_LINUX)
int f = open("/proc/self/cmdline", O_RDONLY);
if (f) {
- const int n = read(f, cmdline, size - 1);
+ const ssize_t n = read(f, cmdline, size - 1);
int i;
- assert(n < size);
+
+ if (n == -1) {
+ debug_printf("Error reading from /proc/self/cmdline: %s",
+ strerror(errno));
+ close(f);
+ cmdline[0] = 0;
+ return FALSE;
+ }
+
+ assert((size_t)n < size);
// The arguments are separated by '\0' chars. Convert them to spaces.
for (i = 0; i < n; i++) {
if (cmdline[i] == 0) {
--
2.17.1
More information about the mesa-dev
mailing list