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 | 4 ++--
filter.c | 5 ++---
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/abook.c b/abook.c
index 3749561..7410f6b 100644
--- 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) {
diff --git a/filter.c b/filter.c
index b6cb98f..eb6e778 100644
--- 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);
--
2.3.0
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Abook-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/abook-devel