rasdaemon: Fix the issue of sprintf data type mismatch in uuid_le()
authorXiaofei Tan <tanxiaofei@huawei.com>
Wed, 20 Oct 2021 06:33:37 +0000 (14:33 +0800)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 1 Apr 2022 09:06:19 +0000 (11:06 +0200)
The data type of sprintf called in the function uuid_le() is mismatch.
Arm64 compiler force it to unsigned char by default, and can work normally.
But if someone compile it with the option -fsigned-char, the function
can't work correctly.

Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
ras-extlog-handler.c
ras-non-standard-handler.c

index 5fd35800966c646ef7ee0631092e05afe360f661..183468734cac0ac2c4f4e837a6b57c83b9deade2 100644 (file)
@@ -152,7 +152,7 @@ static char *uuid_le(const char *uu)
        static const unsigned char le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
 
        for (i = 0; i < 16; i++) {
-               p += sprintf(p, "%.2x", uu[le[i]]);
+               p += sprintf(p, "%.2x", (unsigned char) uu[le[i]]);
                switch (i) {
                case 3:
                case 5:
index 6ccf5bcbd1a8d801e6ad9bc4823a3df8fb4769cc..6d5a6f8259791a3afd4ec0c82dcee4002685862f 100644 (file)
@@ -36,7 +36,7 @@ static char *uuid_le(const char *uu)
        static const unsigned char le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15};
 
        for (i = 0; i < 16; i++) {
-               p += sprintf(p, "%.2x", uu[le[i]]);
+               p += sprintf(p, "%.2x", (unsigned char) uu[le[i]]);
                switch (i) {
                case 3:
                case 5:
@@ -61,7 +61,7 @@ static int uuid_le_cmp(const char *sec_type, const char *uuid2)
                        3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15};
 
        for (i = 0; i < 16; i++)
-               p += sprintf(p, "%.2x", sec_type[le[i]]);
+               p += sprintf(p, "%.2x", (unsigned char) sec_type[le[i]]);
        *p = 0;
        return strncmp(uuid1, uuid2, 32);
 }