Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alloc fail & fix compile warning #105

Merged
merged 7 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can update this to memcpy() as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. How about using qmemdup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your right. I'll change to memcpy.

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