Mercurial > hg > freeDiameter
comparison extensions/app_diameap/diameap_server.c @ 1442:915450ee91c7
fix gcc 9.1.1 compile warnings
Use snprintf instead of strncpy to ensure NUL termination.
Simplify attribute copying to calloc/memcpy instead
of malloc/memset/strncpy/assignment.
Appeases gcc 9.1.1 warnings about strncpy bounds.
author | Luke Mewburn <luke@mewburn.net> |
---|---|
date | Thu, 27 Feb 2020 16:19:24 +1100 |
parents | 0918e88f7c33 |
children |
comparison
equal
deleted
inserted
replaced
1441:6029afe9bacb | 1442:915450ee91c7 |
---|---|
1958 } | 1958 } |
1959 | 1959 |
1960 switch (*toadd) | 1960 switch (*toadd) |
1961 { | 1961 { |
1962 case 1: | 1962 case 1: |
1963 attribute_op = malloc(strlen(op)); | 1963 attribute_op = calloc(strlen(op), sizeof(char *)); |
1964 memset(attribute_op, 0, strlen(op)); | 1964 memcpy(attribute_op, op + 1, strlen(op) - 1); |
1965 strncpy(attribute_op, op + 1, strlen(op) - 1); | |
1966 attribute_op[strlen(op)] = '\0'; | |
1967 break; | 1965 break; |
1968 case 2: | 1966 case 2: |
1969 attribute_op = malloc(strlen(op)); | 1967 attribute_op = calloc(strlen(op), sizeof(char *)); |
1970 memset(attribute_op, 0, strlen(op)); | 1968 memcpy(attribute_op, op, strlen(op) - 1); |
1971 strncpy(attribute_op, op, strlen(op) - 1); | |
1972 attribute_op[strlen(op)] = '\0'; | |
1973 break; | 1969 break; |
1974 default: | 1970 default: |
1975 attribute_op = malloc(strlen(op) + 1); | 1971 attribute_op = calloc(strlen(op) + 1, sizeof(char *)); |
1976 memset(attribute_op, 0, strlen(op) + 1); | 1972 memcpy(attribute_op, op, strlen(op)); |
1977 strcpy(attribute_op, op); | |
1978 attribute_op[strlen(op) + 1] = '\0'; | |
1979 } | 1973 } |
1980 if (strcmp(attribute_op, "=") == 0) | 1974 if (strcmp(attribute_op, "=") == 0) |
1981 { | 1975 { |
1982 *isrule = FALSE; | 1976 *isrule = FALSE; |
1983 *toadd = 2; | 1977 *toadd = 2; |