Skip to content

Commit

Permalink
replace exit() with _exit() (-fanalyzer), some malloc checking
Browse files Browse the repository at this point in the history
(#31)
  • Loading branch information
andy5995 committed May 31, 2021
1 parent c9f924c commit f32d5e1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/cmdlex.l
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ flexYyInput(char *buf,int maxsize)

static Cmdstat cmdstat;

int
yywrap(void)
int yywrap(void);

This comment has been minimized.

Copy link
@andy5995
#ifdef __cplusplus
extern "C"
#endif
int yywrap(void)
{
return 1;
}
Expand Down
36 changes: 28 additions & 8 deletions src/commx.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "defs.h"
#include "commx.h" /*(commxForkExec) */
#include "verbose.h" /*VERB_MISC */
#include "utils.h"
static int commxPid;

static void
Expand All @@ -20,8 +21,9 @@ sigchld (int dummy)
{
fputs (_("Comm program exited.\r\n"), stderr);
verboseOut (VERB_MISC, _("Child returned status %d.\r\n"),
WEXITSTATUS (s));
exit (0);
WEXITSTATUS (s));\

_exit (0);
}
}

Expand Down Expand Up @@ -55,10 +57,19 @@ commxForkExec (const char *cmd, char *ptyslave)
{
char *s;
s = malloc (strlen (cmd) + strlen (ptyslave) + 1);
if (strcmp ("/dev/", ptyslave) == 0)
ptyslave += 5;
sprintf (s, cmd, ptyslave);
forkExec (s);
chk_alloc (s);
if (s != NULL)
{
if (strcmp ("/dev/", ptyslave) == 0)
ptyslave += 5;
sprintf (s, cmd, ptyslave);
forkExec (s);
return;
}
else
{
return;
}
}
#else
void
Expand All @@ -72,7 +83,16 @@ commxForkExec (const char *cmd, char c10, char c01)
c[4] = c01;
c[5] = 0;
s = malloc (strlen (cmd) + strlen (c) + 1);
sprintf (s, cmd, c); /*'%s' -> 'p1' or sth */
forkExec (s);
chk_alloc (s);
if (s != NULL)
{
sprintf (s, cmd, c); /*'%s' -> 'p1' or sth */
forkExec (s);
return;
}
else
{
return;
}
}
#endif
8 changes: 5 additions & 3 deletions src/modemu2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "timeval.h" /*(timeval...) */
#include "commx.h" /*(commxForkExec) */
#include "cmdarg.h" /*cmdarg */
#include "utils.h"

/* socket input processing loop */
static void
Expand Down Expand Up @@ -587,7 +588,8 @@ getPtyMaster (char **line_return)
goto bsd;
}
line = malloc (strlen (temp_line) + 1);
if (!line)
chk_alloc (line);
if (line == NULL)
{
close (pty);
return -1;
Expand Down Expand Up @@ -621,7 +623,8 @@ getPtyMaster (char **line_return)

found:
line = malloc (strlen (name) + 1);
if (line)
chk_alloc (line);
if (line != NULL)
{
strcpy (line, name);
line[5] = 't';
Expand All @@ -644,7 +647,6 @@ Warning: could not change ownership of tty -- pty is insecure!\n"), stderr);
*line_return = line;
return pty;
}
fputs ("malloc(): error allocating memory -- exiting.", stderr);
exit (EXIT_FAILURE);

bail:
Expand Down
2 changes: 1 addition & 1 deletion src/stty.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
static void
sigint (int i)
{
exit (1);
_exit (1);
}

static int pid;
Expand Down

0 comments on commit f32d5e1

Please sign in to comment.