]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/armor: mark dst_end a const pointer
authorKefu Chai <kchai@redhat.com>
Thu, 24 Jun 2021 05:05:22 +0000 (13:05 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 24 Jun 2021 05:05:23 +0000 (13:05 +0800)
to silence GCC-11 warnings like:

../src/common/secret.c: In function ‘set_kernel_secret’:
../src/common/secret.c:65:9: warning: ‘<unknown>’ may be used uninitialized [-Wmaybe-uninitialized]
   65 |   ret = ceph_unarmor(payload, payload+sizeof(payload), secret, secret+secret_len);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../src/common/secret.c:23:
../src/common/armor.h:14:5: note: by argument 2 of type ‘const char *’ to ‘ceph_unarmor’ declared here
   14 | int ceph_unarmor(char *dst, const char *dst_end,
      |     ^~~~~~~~~~~~

see also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100417

this warning is false positive. but it's still annoying.

since semantically, we are changing the dst buffer, and the dst_end
specify the non-inclusive upper bound of the output buffer, this
change is not quite wrong by changing the type of this pointer
from a pointer to a const char to a constant pointer to a (mutable) char.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/armor.c
src/common/armor.h

index 706e01e7f221090baf16d843bf685eefb83e7d3d..3508b82e353d266a40f57e15a02e5a337923c810 100644 (file)
@@ -45,7 +45,7 @@ static int set_str_val(char **pdst, const char *end, char c)
        return 0;
 }
 
-int ceph_armor_line_break(char *dst, const char *dst_end, const char *src, const char *end, int line_width)
+int ceph_armor_line_break(char *dst, char * const dst_end, const char *src, const char *end, int line_width)
 {
        int olen = 0;
        int line = 0;
@@ -91,12 +91,12 @@ int ceph_armor_line_break(char *dst, const char *dst_end, const char *src, const
        return olen;
 }
 
-int ceph_armor(char *dst, const char *dst_end, const char *src, const char *end)
+int ceph_armor(char *dst, char * const dst_end, const char *src, const char *end)
 {
        return ceph_armor_line_break(dst, dst_end, src, end, 0);
 }
 
-int ceph_unarmor(char *dst, const char *dst_end, const char *src, const char *end)
+int ceph_unarmor(char *dst, char * const dst_end, const char *src, const char *end)
 {
        int olen = 0;
 
index 340b33aaf57c2b86a7852abc64e3e89375fe0c39..f0ee9f9b20969d9d926c269a7f19a1e70a888390 100644 (file)
@@ -5,14 +5,14 @@
 extern "C" {
 #endif
 
-int ceph_armor(char *dst, const char *dst_end,
-              const char *src, const char *end);
+int ceph_armor(char *dst, char * const dst_end,
+              const char * src, const char *end);
 
-int ceph_armor_linebreak(char *dst, const char *dst_end,
+int ceph_armor_linebreak(char *dst, char * const dst_end,
               const char *src, const char *end,
               int line_width);
-int ceph_unarmor(char *dst, const char *dst_end,
-                const char *src, const char *end);
+int ceph_unarmor(char *dst, char * const dst_end,
+                const char *src, const char * const end);
 #ifdef __cplusplus
 }
 #endif