summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2019-03-06 20:56:27 +1030
committerDaniel Jones <admin@danieljon.es>2019-03-06 20:56:27 +1030
commit3eee916c5cff8ca0bd9b0d7abbf36d003c1212ec (patch)
tree87c7e67664437860db65036ec8b483228a3e6735
parent81684d580370b9f45643078469beab3c73d29db3 (diff)
downloadurlopener-3eee916c5cff8ca0bd9b0d7abbf36d003c1212ec.tar.gz
urlopener-3eee916c5cff8ca0bd9b0d7abbf36d003c1212ec.zip
removed unneeded assignment and used a define for buffer sizes
-rw-r--r--urlopen.c10
1 files 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 <signal.h>
#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)
{