comparison libtomcrypt/demos/sizes.c @ 1733:d529a52b2f7c coverity coverity

merge coverity from main
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 Jun 2020 21:07:34 +0800
parents e9dba7abd939
children
comparison
equal deleted inserted replaced
1643:b59623a64678 1733:d529a52b2f7c
40 /* get and print the length of the names (and sizes) list */ 40 /* get and print the length of the names (and sizes) list */
41 if (crypt_list_all_sizes(NULL, &sizes_list_len) != 0) exit(EXIT_FAILURE); 41 if (crypt_list_all_sizes(NULL, &sizes_list_len) != 0) exit(EXIT_FAILURE);
42 printf(" need to allocate %u bytes \n\n", sizes_list_len); 42 printf(" need to allocate %u bytes \n\n", sizes_list_len);
43 43
44 /* get and print the names (and sizes) list */ 44 /* get and print the names (and sizes) list */
45 sizes_list = malloc(sizes_list_len); 45 if ((sizes_list = malloc(sizes_list_len)) == NULL) exit(EXIT_FAILURE);
46 if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE); 46 if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE);
47 printf(" supported sizes:\n\n%s\n\n", sizes_list); 47 printf(" supported sizes:\n\n%s\n\n", sizes_list);
48 free(sizes_list);
48 } else if (argc == 2) { 49 } else if (argc == 2) {
49 if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { 50 if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
50 char* base = strdup(basename(argv[0])); 51 char* base = strdup(basename(argv[0]));
51 printf("Usage: %s [-a] [-s name]\n\n", base); 52 printf("Usage: %s [-a] [-s name]\n\n", base);
52 _print_line("<no argument>", "The old behavior of the demo"); 53 _print_line("<no argument>", "The old behavior of the demo");
58 char *sizes_list; 59 char *sizes_list;
59 unsigned int sizes_list_len; 60 unsigned int sizes_list_len;
60 /* get and print the length of the names (and sizes) list */ 61 /* get and print the length of the names (and sizes) list */
61 if (crypt_list_all_sizes(NULL, &sizes_list_len) != 0) exit(EXIT_FAILURE); 62 if (crypt_list_all_sizes(NULL, &sizes_list_len) != 0) exit(EXIT_FAILURE);
62 /* get and print the names (and sizes) list */ 63 /* get and print the names (and sizes) list */
63 sizes_list = malloc(sizes_list_len); 64 if ((sizes_list = malloc(sizes_list_len)) == NULL) exit(EXIT_FAILURE);
64 if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE); 65 if (crypt_list_all_sizes(sizes_list, &sizes_list_len) != 0) exit(EXIT_FAILURE);
65 printf("%s\n", sizes_list); 66 printf("%s\n", sizes_list);
67 free(sizes_list);
66 } 68 }
67 } else if (argc == 3) { 69 } else if (argc == 3) {
68 if (strcmp(argv[1], "-s") == 0) { 70 if (strcmp(argv[1], "-s") == 0) {
69 unsigned int size; 71 unsigned int size;
70 if (crypt_get_size(argv[2], &size) != 0) exit(EXIT_FAILURE); 72 if (crypt_get_size(argv[2], &size) != 0) exit(EXIT_FAILURE);