fix: string constants (-Wwrite-strings)
authorMichael Jeanson <mjeanson@efficios.com>
Fri, 26 Mar 2021 19:34:21 +0000 (15:34 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 31 Mar 2021 18:21:43 +0000 (14:21 -0400)
Do not use an anonymous string literal with a non-const char pointer as
this will discard the implicit const, use static non-const string
instead when appropriate. Otherwise, we could end up trying to write to
a string constant.

Change-Id: Ie2bb0e5ab7978930f9edcdb379bd181caaacc15c
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
doc/examples/easy-ust/sample_component_provider.h
doc/examples/gen-tp/sample_tracepoint.tp
liblttng-ust/lttng-context-procname.c
liblttng-ust/ust-events-internal.h
snprintf/vfprintf.c
tests/compile/test-app-ctx/hello.c

index edfac8f58706bcaa665d25a474ef3234cb516e6e..d457664d8aa1fa9c9daf3750a816a7027b003612 100644 (file)
@@ -74,7 +74,7 @@ TRACEPOINT_EVENT(
         *              TP_ARGS() is valid to mean no arguments
         *              TP_ARGS( void ) is valid too
         */
-       TP_ARGS(char *, text),
+       TP_ARGS(const char *, text),
        /*
         * TP_FIELDS describes how to write the fields of the trace event.
         * You can use the args here
index fa7d18a5080a0ca72c5bb8d9927915dd597daefd..22f7713f972a7c1d7ca7dc4f04ef8e7ee8aae523 100644 (file)
@@ -1,7 +1,7 @@
 TRACEPOINT_EVENT(
        sample_tracepoint,
        message, // C++ Style comment
-       TP_ARGS(char *, text),
+       TP_ARGS(const char *, text),
        TP_FIELDS(
                ctf_string(message, text)
                  )
index a65585deb981656d764303f339325c9df503412c..53c42d9eb67e79325e1e23280335c8af66d8447a 100644 (file)
@@ -37,7 +37,7 @@ static DEFINE_URCU_TLS(procname_array, cached_procname);
 static DEFINE_URCU_TLS(int, procname_nesting);
 
 static inline
-char *wrapper_getprocname(void)
+const char *wrapper_getprocname(void)
 {
        int nesting = CMM_LOAD_SHARED(URCU_TLS(procname_nesting));
 
@@ -76,7 +76,7 @@ void procname_record(struct lttng_ust_ctx_field *field,
                 struct lttng_ust_lib_ring_buffer_ctx *ctx,
                 struct lttng_ust_channel_buffer *chan)
 {
-       char *procname;
+       const char *procname;
 
        procname = wrapper_getprocname();
        chan->ops->event_write(ctx, procname, LTTNG_UST_ABI_PROCNAME_LEN, 1);
index daf72b9de0b214e76a3a26c414e3bf9da9286ed8..786b650d32fba189cef5c073eb2ff77e68521958 100644 (file)
@@ -250,14 +250,14 @@ struct lttng_event_notifier_group {
 };
 
 struct lttng_transport {
-       char *name;
+       const char *name;
        struct cds_list_head node;
        struct lttng_ust_channel_buffer_ops ops;
        const struct lttng_ust_lib_ring_buffer_config *client_config;
 };
 
 struct lttng_counter_transport {
-       char *name;
+       const char *name;
        struct cds_list_head node;
        struct lttng_counter_ops ops;
        const struct lib_counter_config *client_config;
index 5cb356c2beda6095cdd47113c968b5ad9bc67082..c2b07eb0bce59a2a0cf569de8a9cd6a4955a0294 100644 (file)
@@ -35,6 +35,9 @@
 #include "fvwrite.h"
 #include "various.h"
 
+static char null_str[] = "(null)";
+static char bad_base_str[] = "bug in ust_safe_vfprintf: bad base";
+
 union arg {
        int                     intarg;
        unsigned int            uintarg;
@@ -715,7 +718,7 @@ fp_common:
                        goto nosign;
                case 's':
                        if ((cp = GETARG(char *)) == NULL)
-                               cp = "(null)";
+                               cp = null_str;
                        if (prec >= 0) {
                                /*
                                 * can't use strlen; can only look for the
@@ -802,7 +805,7 @@ number:                     if ((dprec = prec) >= 0)
                                        break;
 
                                default:
-                                       cp = "bug in ust_safe_vfprintf: bad base";
+                                       cp = bad_base_str;
                                        size = strlen(cp);
                                        goto skipsize;
                                }
index c08fa8dd0347eef348aa0ebafa389796d9397264..da347714d5d8fc68906bc38ebcc75ca1406bf9e2 100644 (file)
@@ -243,9 +243,10 @@ void test_get_value(struct lttng_ust_ctx_field *field,
        }
 }
 
+static char myprovider_name[] = "$app.myprovider";
 struct lttng_ust_context_provider myprovider = {
        .struct_size = sizeof(struct lttng_ust_context_provider),
-       .name = "$app.myprovider",
+       .name = myprovider_name,
        .get_size = test_get_size,
        .record = test_record,
        .get_value = test_get_value,
This page took 0.0291 seconds and 4 git commands to generate.