-
Notifications
You must be signed in to change notification settings - Fork 168
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
Conversation
strncpy(newstr, str, strsize) => memcpy Because strsize is computed in 302 line, if call strncpy then recompute len.
src/utilities/qsocket.c
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@@ -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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Thanks for the PR. I left some minor comments. |
The comment you left is very helpful. |
src/utilities/qstring.c
Outdated
@@ -388,10 +393,8 @@ char *qstrdup_between(const char *str, const char *start, const char *end) { | |||
|
|||
int len = e - s; | |||
|
|||
char *buf = (char *) malloc(sizeof(char) * (len + 1)); | |||
strncpy(buf, s, len); | |||
char *buf = qmemdup(s, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it need to be len + 1
and also need NULL check for the buf?
I'd like to focus on the NULL return on this PR. Let's not mix them in a single PR.
Can you revert this for now and just add the NULL check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/utilities/qio.c
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
src/utilities/qstring.c
Outdated
|
||
memcpy(buf, s, len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also let's keep this to strncpy() for now.
memcpy => strncpy src/utilities/qio.c :306 src/utilities/qstring.c :400
I applied the requests. Thanks for the good advice. |
Thanks for working with me. A Great PR!!! |
I fix some compile warning and alloc fail(#104 ).
But still occur two compile warning. Do you want to fix this complie warning?
Here's my environment