Skip to content

Commit 42ad220

Browse files
committed
vlogger: strdup error check
1 parent ffa7681 commit 42ad220

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

vlogger.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <errno.h>
12
#include <stdio.h>
23
#include <stdlib.h>
34
#include <string.h>
@@ -49,8 +50,6 @@ CODE facilitynames[] = {
4950
{ 0, -1 }
5051
};
5152

52-
static char *tag;
53-
5453
static void
5554
strpriority(char *s, int *facility, int *level)
5655
{
@@ -74,7 +73,7 @@ strpriority(char *s, int *facility, int *level)
7473
int
7574
main(int argc, char *argv[])
7675
{
77-
char c, *p, *argv0;
76+
char c, *p, *argv0, *tag;
7877
int facility = LOG_DAEMON;
7978
int level = LOG_INFO;
8079

@@ -83,7 +82,10 @@ main(int argc, char *argv[])
8382
if (((p = strrchr(*argv, '/')) && !strncmp(p+1, "run", 3)) &&
8483
(*p = 0, (p = strrchr(*argv, '/')) && !strncmp(p+1, "log", 3)) &&
8584
(*p = 0, (p = strrchr(*argv, '/'))) != 0) {
86-
tag = strdup(p+1);
85+
if (!(tag = strdup(p+1))) {
86+
fprintf(stderr, "vlogger: strdup: %s\n", strerror(errno));
87+
exit(1);
88+
}
8789
}
8890

8991
while ((c = getopt(argc, argv, "p:t:")) != -1)

0 commit comments

Comments
 (0)