Skip to content

Commit

Permalink
Alloc fail & fix compile warning (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hojun-Cho authored Jul 12, 2023
1 parent 2f43e41 commit 1826858
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/utilities/qsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ bool qsocket_close(int sockfd, int timeoutms) {
char buf[1024];
while (true) {
ssize_t read = qio_read(sockfd, buf, sizeof(buf), timeoutms);
DEBUG("Throw %zu bytes from dummy input stream.", read);
if (read <= 0)
break;DEBUG("Throw %zu bytes from dummy input stream.", read);
break;
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/utilities/qstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ char *qstrreplace(const char *mode, char *srcstr, const char *tokstr,
if (method == 't') { /* Token replace */
maxstrlen = strlen(srcstr) * ((strlen(word) > 0) ? strlen(word) : 1);
newstr = (char *) malloc(maxstrlen + 1);
if (newstr == NULL)
return NULL;

for (srcp = (char *) srcstr, newp = newstr; *srcp; srcp++) {
for (tokenp = (char *) tokstr; *tokenp; tokenp++) {
Expand All @@ -274,6 +276,9 @@ char *qstrreplace(const char *mode, char *srcstr, const char *tokstr,
maxstrlen = strlen(srcstr);
}
newstr = (char *) malloc(maxstrlen + 1);
if (newstr == NULL)
return NULL;

tokstrlen = strlen(tokstr);

for (srcp = srcstr, newp = newstr; *srcp; srcp++) {
Expand Down Expand Up @@ -389,9 +394,11 @@ char *qstrdup_between(const char *str, const char *start, const char *end) {
int len = e - s;

char *buf = (char *) malloc(sizeof(char) * (len + 1));
if (buf == NULL)
return NULL;

strncpy(buf, s, len);
buf[len] = '\0';

return buf;
}

Expand Down Expand Up @@ -869,6 +876,7 @@ char *qstr_conv_encoding(const char *str, const char *fromcode,
char *tostr = (char *) malloc(tosize);
if (tostr == NULL)
return NULL;

char *tostr1 = tostr;

iconv_t it = iconv_open(tocode, fromcode);
Expand Down
6 changes: 6 additions & 0 deletions src/utilities/qtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ char *qtime_localtime_strf(char *buf, int size, time_t utctime,
char *qtime_localtime_str(time_t utctime) {
int size = sizeof(char) * (CONST_STRLEN("00-Jan-0000 00:00:00 +0000") + 1);
char *timestr = (char *) malloc(size);
if (timestr == NULL)
return NULL;

qtime_localtime_strf(timestr, size, utctime, "%d-%b-%Y %H:%M:%S %z");
return timestr;
}
Expand Down Expand Up @@ -172,6 +175,9 @@ char *qtime_gmt_str(time_t utctime) {
int size = sizeof(char)
* (CONST_STRLEN("Mon, 00 Jan 0000 00:00:00 GMT") + 1);
char *timestr = (char *) malloc(size);
if (timestr == NULL)
return NULL;

qtime_gmt_strf(timestr, size, utctime, "%a, %d %b %Y %H:%M:%S GMT");
return timestr;
}
Expand Down

0 comments on commit 1826858

Please sign in to comment.