[glib: 1/3] tests: Fix a compiler warning about string+int arithmetic
- From: Sebastian Dröge <sdroege src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/3] tests: Fix a compiler warning about string+int arithmetic
- Date: Mon, 24 Feb 2020 21:53:29 +0000 (UTC)
commit 99a325356d299d05dfafb90056cb51eed64677cb
Author: Philip Withnall <withnall endlessm com>
Date: Wed Dec 13 12:20:04 2017 +0000
tests: Fix a compiler warning about string+int arithmetic
Clang warns about string+int not appending to the string (to try and
catch newbie mistakes). While this test didn’t expect that to happen, it
was substituting the same constant string in multiple places for no good
reason. Switch to a single static const string, which should also fix
the compiler warning.
We have to define the string length since it’s used in various
stack-allocated array lengths. This is the easiest fix without more
major refactoring of the test to be less 90s.
Also make things a bit more static.
Signed-off-by: Philip Withnall <withnall endlessm com>
gio/tests/unix-streams.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/gio/tests/unix-streams.c b/gio/tests/unix-streams.c
index 65eedb368..5ec829919 100644
--- a/gio/tests/unix-streams.c
+++ b/gio/tests/unix-streams.c
@@ -22,6 +22,7 @@
#include <gio/gio.h>
#include <gio/gunixinputstream.h>
#include <gio/gunixoutputstream.h>
+#include <glib.h>
#include <glib/glib-unix.h>
#include <signal.h>
#include <stdlib.h>
@@ -29,7 +30,8 @@
#include <unistd.h>
#include <fcntl.h>
-#define DATA "abcdefghijklmnopqrstuvwxyz"
+/* sizeof(DATA) will give the number of bytes in the array, plus the terminating nul */
+static const gchar DATA[] = "abcdefghijklmnopqrstuvwxyz";
int writer_pipe[2], reader_pipe[2];
GCancellable *writer_cancel, *reader_cancel, *main_cancel;
@@ -118,8 +120,8 @@ reader_thread (gpointer user_data)
g_assert_not_reached ();
}
-char main_buf[sizeof (DATA)];
-gssize main_len, main_offset;
+static char main_buf[sizeof (DATA)];
+static gssize main_len, main_offset;
static void main_thread_read (GObject *source, GAsyncResult *res, gpointer user_data);
static void main_thread_skipped (GObject *source, GAsyncResult *res, gpointer user_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]