From 3eee916c5cff8ca0bd9b0d7abbf36d003c1212ec Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Wed, 6 Mar 2019 20:56:27 +1030 Subject: removed unneeded assignment and used a define for buffer sizes --- urlopen.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/urlopen.c b/urlopen.c index 8b549ff..f98005c 100644 --- a/urlopen.c +++ b/urlopen.c @@ -23,6 +23,7 @@ #include #define LEN(arr) ((int) (sizeof (arr) / sizeof (arr)[0])) +#define BUFFSIZE 256 /* size of malloc buffers (max program/extension list length) */ char *programs[][2] = { @@ -67,10 +68,10 @@ getext(char *url) { for (int i = 0; i < LEN(programs); i++) { - char *buff = malloc(256); + char *buff = malloc(BUFFSIZE); if (buff == NULL) return 0; - strncpy(buff, programs[i][0], 255); + strncpy(buff, programs[i][0], BUFFSIZE-1); char *t = strtok(buff, ","); while (t != NULL) { @@ -114,7 +115,7 @@ main(int argc, char *argv[]) fclose(stdout); fclose(stderr); char *args[20]; - char *buff = malloc(256); + char *buff = malloc(BUFFSIZE); if (buff == NULL) { perror("malloc"); @@ -125,9 +126,8 @@ main(int argc, char *argv[]) * so we tokenise the string and add each part to an array * that we will use in execvp */ - strncpy(buff, programs[ext][1], 255); + strncpy(buff, programs[ext][1], BUFFSIZE-1); char *t = strtok(buff, " "); - args[0] = t; int z = 0; while (t != NULL) { -- cgit v1.2.3