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

Conversation

Hojun-Cho
Copy link
Contributor

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

  • GCC : 13.1.1
  • Arch: Linux arch 6.3.8-arch1-1 x86_64
extensions/qconfig.c: In function ‘qconfig_parse_file’:
extensions/qconfig.c:165:48: warning: ‘%s’ directive output may be truncated writing up to 4094 bytes into a region of size between 1 and 4095 [-Wformat-truncation=]
  165 |                 snprintf(tmp, sizeof(tmp), "%s/%s", dir, buf);
      |                                                ^~        ~~~
extensions/qconfig.c:165:17: note: ‘snprintf’ output between 2 and 8190 bytes into a destination of size 4096
  165 |                 snprintf(tmp, sizeof(tmp), "%s/%s", dir, buf);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include -I/usr/local/include -I../include/qlibc -I./internal -c -o utilities/qtime.o
 utilities/qtime.c                                                                                                                                                                             
In file included from /usr/include/bits/libc-header-start.h:33,
                 from /usr/include/stdio.h:27,
                 from utilities/qtime.c:36:
/usr/include/features.h:195:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]  
  195 | # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"                                         

@@ -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

@@ -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.

@wolkykim
Copy link
Owner

Thanks for the PR. I left some minor comments.

@Hojun-Cho
Copy link
Contributor Author

The comment you left is very helpful.

@@ -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);
Copy link
Owner

@wolkykim wolkykim Jul 12, 2023

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -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.


memcpy(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.

also let's keep this to strncpy() for now.

memcpy => strncpy
    src/utilities/qio.c :306
    src/utilities/qstring.c :400
@Hojun-Cho
Copy link
Contributor Author

I applied the requests. Thanks for the good advice.

@Hojun-Cho Hojun-Cho requested a review from wolkykim July 12, 2023 07:05
@wolkykim wolkykim merged commit 1826858 into wolkykim:master Jul 12, 2023
1 check passed
@wolkykim
Copy link
Owner

Thanks for working with me. A Great PR!!!

@Hojun-Cho Hojun-Cho deleted the alloc-fail branch July 12, 2023 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants