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 3 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
2 changes: 1 addition & 1 deletion src/utilities/qio.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ ssize_t qio_puts(int fd, const char *str, int timeoutms) {
char *newstr = (char *) malloc(strsize + 1 + 1);
if (newstr == NULL)
return -1;
strncpy(newstr, str, strsize);
memcpy(newstr, str, strsize);
Copy link
Owner

Choose a reason for hiding this comment

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

Can you revert this line please? I'd prefer not to mix the change in this PR.

newstr[strsize] = '\n';
newstr[strsize + 1] = '\0';
ssize_t ret = qio_write(fd, newstr, strsize + 1, timeoutms);
Expand Down
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);
Copy link
Owner

Choose a reason for hiding this comment

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

seems the indentation is not lined up.

Copy link
Owner

Choose a reason for hiding this comment

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

qlibc uses spaces, please ignore using tabs

Copy link
Contributor Author

@Hojun-Cho Hojun-Cho Jul 12, 2023

Choose a reason for hiding this comment

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

Oops, didn't realize that, thanks for the heads up. Fixed

if (read <= 0)
break;DEBUG("Throw %zu bytes from dummy input stream.", read);
break;
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/utilities/qstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ 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 +277,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,6 +395,9 @@ 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';

Expand Down Expand Up @@ -869,6 +878,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