]> git.deb.at Git - pkg/abook.git/commitdiff
Fix "Allocator sizeof operand mismatch"
authorPeter Wu <peter@lekensteyn.nl>
Mon, 16 Feb 2015 18:41:56 +0000 (19:41 +0100)
committerRaphaël Droz <raphael.droz+floss@gmail.com>
Sun, 22 Feb 2015 00:20:42 +0000 (21:20 -0300)
sizeof should be used on the data that will be stored, not the pointer.
Luckily the pointers are larger than the actual data, so there is no
security issue here.

Remove sizeof(char) as it is equal to 1 by the C standard.

Caught by Clang Static Analyzer.

abook.c
filter.c

diff --git a/abook.c b/abook.c
index 37495613125918debf97c9541ab79a7c5c7c3579..7410f6b50747f53b074f819c3be3a87168192764 100644 (file)
--- a/abook.c
+++ b/abook.c
@@ -420,8 +420,8 @@ parse_command_line(int argc, char **argv)
                        fprintf(stderr, _("Invalid custom format string\n"));
                        exit(EXIT_FAILURE);
                }
-               parsed_custom_format = (char *)malloc(FORMAT_STRING_LEN * sizeof(char*));
-               custom_format_fields = (enum field_types *)malloc(FORMAT_STRING_MAX_FIELDS * sizeof(enum field_types *));
+               parsed_custom_format = (char *)malloc(FORMAT_STRING_LEN);
+               custom_format_fields = (enum field_types *)malloc(FORMAT_STRING_MAX_FIELDS * sizeof(enum field_types));
                parse_custom_format(custom_format, parsed_custom_format, custom_format_fields);
        }
        if(optind < argc) {
index b6cb98f9ba532d4ea8ac0a583a1f52157de93c1e..eb6e778042f9c63cef421e0306497868e0ef0b80 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -2723,11 +2723,10 @@ extern char custom_format[FORMAT_STRING_LEN];
 static int
 custom_export_database(FILE *out, struct db_enumerator e)
 {
-       char *format_string =
-         (char *)malloc(FORMAT_STRING_LEN * sizeof(char*));
+       char *format_string = (char *)malloc(FORMAT_STRING_LEN);
 
        enum field_types *ft =
-         (enum field_types *)malloc(FORMAT_STRING_MAX_FIELDS * sizeof(enum field_types *));
+         (enum field_types *)malloc(FORMAT_STRING_MAX_FIELDS * sizeof(enum field_types));
 
        parse_custom_format(custom_format, format_string, ft);