Skip to content

Commit

Permalink
trurl: on strdup() failures, exit immediately
Browse files Browse the repository at this point in the history
Rather than continuing and acting weirdly.
  • Loading branch information
bagder committed Aug 16, 2024
1 parent ae00a7a commit bbf73f6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion trurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ static void trim(struct option *o)
removed. Get a copy and edit that accordingly. */
temp = strdup(ptr);
if(!temp)
return; /* out of memory, bail out */
errorf(o, ERROR_MEM, "out of memory");
temp[inslen - 2] = '*';
temp[inslen - 1] = '\0';
ptr = temp;
Expand Down Expand Up @@ -1207,6 +1207,8 @@ static void trim(struct option *o)
qpairs[i].len = 0;
qpairsdec[i].str = strdup(""); /* marked as deleted */
qpairsdec[i].len = 0;
if(!qpairs[i].str || !qpairsdec[i].str)
errorf(o, ERROR_MEM, "out of memory");
}
}
free(temp);
Expand Down Expand Up @@ -1432,6 +1434,8 @@ static void replace(struct option *o)
qpairs[i].str = strdup("");
qpairsdec[i].len = 0;
qpairsdec[i].str = strdup("");
if(!qpairs[i].str || !qpairsdec[i].str)
errorf(o, ERROR_MEM, "out of memory");
continue;
}
struct string *pdec =
Expand Down

0 comments on commit bbf73f6

Please sign in to comment.