I added a free statement above the assignment and now I get Kept storage min_string passed as only param: free (min_string) storage is transferred to a non-temporary reference after being passed as keep parameter. The storage may be released or new aliases created. (Use -kepttrans to inhibit warning) Storage min_string becomes kept
Next I get new messages about Dead storage options->low_charset passed as out parameter to free: I did switch to strtoul and did a cast: options->starthere = (size_t)strtoul(argv[1], &endptr, 10); Yes I check the return values too. I also switched to malloc: min_string = malloc(sizeof(char)*options->starthere + 1); Here is the updated code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> static const char lowercase[] = "alphaomegaalphaomegaalpha1"; typedef struct opts_struct { char *low_charset; size_t clen; char *startstring; size_t starthere; char *min_string; } options_type; static void fill_strings(options_type *options) { size_t i; char *min_string; min_string = malloc(sizeof(char)*options->starthere + 1); if (min_string == NULL) { printf("can't allocate memory for min_string\n"); exit(EXIT_FAILURE); } min_string[options->starthere] = '\0'; if (options->startstring != NULL) for (i = 0; i < options->starthere; i++) min_string[i] = options->startstring[i]; free(options->min_string); options->min_string = min_string; free(min_string); } int main(/*@ unused @*/ int argc, char **argv) { char *charset; char *starthere = NULL; char *endptr; options_type *options = NULL; static const options_type options_type0; options = calloc(200, sizeof(*options)); if (options == NULL) { printf("unable to allocate memory for options\n"); exit(EXIT_FAILURE); } *options = options_type0; charset = malloc(sizeof(char)*27); if (charset == NULL) { printf("can't allocate memory\n"); exit(EXIT_FAILURE); } memset(charset, 0, sizeof(charset)); memcpy(charset, lowercase, 26); options->starthere = (size_t)strtoul(argv[1], &endptr, 10); if ((errno == ERANGE) || (errno != 0 && options->starthere == 0)) { perror("strtol"); exit(EXIT_FAILURE); } if (endptr == argv[1]) { fprintf(stderr, "No numbers were found\n"); exit(EXIT_FAILURE); } starthere = argv[2]; free(options->low_charset); options->low_charset = charset; options->clen = charset ? strlen(charset) : 0; free(options->startstring); options->startstring = starthere; fill_strings(options); free(charset); free(options); return 0; } _______________________________________________ splint-discuss mailing list splint-discuss@mail.cs.virginia.edu http://www.cs.virginia.edu/mailman/listinfo/splint-discuss