@@ -1148,12 +1148,11 @@ int main(int argc, char **argv)
FGETS(ans, sizeof(ans), stdin);
ans[strlen(ans) - 1] = 0;
- name = malloc((strlen(ans) + 1) * sizeof(char));
+ name = strdup(ans);
if (name == NULL) {
- fprintf(stderr, "couldn't malloc string.\n");
+ fprintf(stderr, "couldn't strdup string.\n");
break;
}
- strcpy(name, ans);
printf("state? ");
FGETS(ans, sizeof(ans), stdin);
@@ -1296,12 +1295,11 @@ int main(int argc, char **argv)
FGETS(ans, sizeof(ans), stdin);
ans[strlen(ans) - 1] = 0;
- name = malloc((strlen(ans) + 1) * sizeof(char));
+ name = strdup(ans);
if (!name) {
- fprintf(stderr, "couldn't malloc string.\n");
+ fprintf(stderr, "couldn't strdup string.\n");
break;
}
- strcpy(name, ans);
printf("port? ");
FGETS(ans, sizeof(ans), stdin);
@@ -117,12 +117,11 @@ int insert_id(const char *id, int push)
char *newid = 0;
int error;
- newid = (char *)malloc(strlen(id) + 1);
+ newid = strdup(id);
if (!newid) {
yyerror("out of memory");
return -1;
}
- strcpy(newid, id);
if (push)
error = queue_push(id_queue, (queue_element_t) newid);
else
@@ -486,12 +486,11 @@ int main(int argc, char **argv)
}
ans[strlen(ans) - 1] = 0;
- name = malloc((strlen(ans) + 1) * sizeof(char));
+ name = strdup(ans);
if (name == NULL) {
- fprintf(stderr, "couldn't malloc string.\n");
+ fprintf(stderr, "couldn't strdup string.\n");
break;
}
- strcpy(name, ans);
printf("state? ");
if (fgets(ans, sizeof(ans), stdin) == NULL) {
Use strdup(3) instead of allocating memory and then manually copying the content. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> --- checkpolicy/checkpolicy.c | 10 ++++------ checkpolicy/policy_define.c | 3 +-- checkpolicy/test/dispol.c | 5 ++--- 3 files changed, 7 insertions(+), 11 deletions(-)