diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2016-10-07 17:41:01 +0100 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2016-10-13 17:20:28 +0100 |
commit | 8db5ca900fd84ea1c055cd15600dfe352e542df5 (patch) | |
tree | 72c37822da382f513fff45acc5d90811c5f9701f /tools | |
parent | cc7df2fbf944d53ec6bbed499ef1e054bdfa0eb9 (diff) |
Be more const-correct
As a general design principle, strings that we aren't going to modify
should usually be const. When compiling with -Wwrite-strings, quoted
string constants are of type "const char *", causing compiler warnings
when they are assigned to char * variables.
Unfortunately, we need to add casts in a few places:
* _dbus_list_append(), _dbus_test_oom_handling() and similar generic
"user-data" APIs take a void *, not a const void *, so we have
to cast
* For historical reasons the execve() family of functions take a
(char * const *), i.e. a constant pointer to an array of mutable
strings, so again we have to cast
* _dbus_spawn_async_with_babysitter similarly takes a char **,
although we can make it a little more const-correct by making it
take (char * const *) like execve() does
This also incorporates a subsequent patch by Thomas Zimmermann to
put various string constants in static storage, which is a little
more efficient.
Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97357
Diffstat (limited to 'tools')
-rw-r--r-- | tools/dbus-launch-win.c | 6 | ||||
-rw-r--r-- | tools/dbus-launch-x11.c | 2 | ||||
-rw-r--r-- | tools/dbus-uuidgen.c | 3 |
3 files changed, 6 insertions, 5 deletions
diff --git a/tools/dbus-launch-win.c b/tools/dbus-launch-win.c index 1dfd0954c..34837c12b 100644 --- a/tools/dbus-launch-win.c +++ b/tools/dbus-launch-win.c @@ -38,7 +38,7 @@ #define wcscpy_s my_wcscpy_s static errno_t -wcscat_s (wchar_t *dest, size_t size, wchar_t *src) +wcscat_s (wchar_t *dest, size_t size, const wchar_t *src) { assert (sizeof (wchar_t) * (wcslen (dest) + wcslen (src) + 1) <= size); wcscat (dest, src); @@ -47,7 +47,7 @@ wcscat_s (wchar_t *dest, size_t size, wchar_t *src) static errno_t -wcscpy_s (wchar_t *dest, size_t size, wchar_t *src) +wcscpy_s (wchar_t *dest, size_t size, const wchar_t *src) { assert (sizeof (wchar_t) * (wcslen (src) + 1) <= size); wcscpy (dest, src); @@ -87,7 +87,7 @@ main (int argc, char **argv) wchar_t dbusDaemonPath[MAX_PATH * 2 + 1]; wchar_t command[MAX_PATH * 2 + 1]; wchar_t *p; - wchar_t *daemon_name; + const wchar_t *daemon_name; int result; #ifdef DBUS_WINCE diff --git a/tools/dbus-launch-x11.c b/tools/dbus-launch-x11.c index 198884868..e8b29f882 100644 --- a/tools/dbus-launch-x11.c +++ b/tools/dbus-launch-x11.c @@ -52,7 +52,7 @@ x_io_error_handler (Display *local_xdisplay) static void remove_prefix (char *s, - char *prefix) + const char *prefix) { int plen; diff --git a/tools/dbus-uuidgen.c b/tools/dbus-uuidgen.c index 03ce55360..744bbeb0e 100644 --- a/tools/dbus-uuidgen.c +++ b/tools/dbus-uuidgen.c @@ -28,7 +28,8 @@ #include <dbus/dbus.h> static void -usage (char *name, int ecode) +usage (const char *name, + int ecode) { if (name == NULL) name = "dbus-uuidgen"; |