-
Notifications
You must be signed in to change notification settings - Fork 603
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
qrenc: silence gcc -Wstringop-overflow warning #147
base: master
Are you sure you want to change the base?
Conversation
Thank you @sgn. According to this stackoverflow, we could use strcat() instead of strncat(). Actually, we just use static strings as the src of strncat() and in these case there's no need to calculate the length of the src strings by hand. Can I have your thoughts? |
On 2019-12-11 21:04:58-0800, Kentaro Fukuchi ***@***.***> wrote:
Actually, we just use static strings as the src of strncat() and in
these case there's no need to calculate the length of the src
strings by hand.
Yes, we could use strcat(3) instead of strncat(3) in this case.
And, it could be simpler to use strcat(3) instead.
After a harder thought, I think strcat(3) isn't really optimal in this
case.
With strcat(3), we're repeatedly traverse through buffer.
I think it's better to use memcpy instead.
I could prepare the patch myself if you think it's a good idea.
…--
Danh
|
7cee9f4
to
f5b0a0e
Compare
Hi @fukuchi, I've pushed a series of change to replace The last commit is intended for not altering options in |
aec9bb6
to
8239441
Compare
Hi, |
8239441
to
1d73355
Compare
I think the buffer is always large enough. Let's just use |
Clean up all inconsistence code-style for the next refactor: - whitespace after keyword and before open brace - no whitespace after ( and before ) - whitespace around binary operator
Modern compiler can optimise those calls, let's not burden ourselves with this counting.
On a modern compiler, the compiler should be able to figure out both black_s and white_s are compile time constant and fold this change to constant. And we can easier argue why we need to allow that much of memory. This change also help if we decide to support another kind of weird terminal color scheme in future.
1d73355
to
22b6819
Compare
strncat(3) needs to traverse through the buffer to append the string into the end of old string. This will have a big performance penalty when we have a very large input. Replace it with strcpy(3) and a pointer to track the end of current buffer. Accidently, this change also silence gcc's -Wstringop-overflow warning, since gcc thinks our issue to strncat(3) to stop right at the NULL terminator maybe an error.
We're reseting size to 1 in writeANSI and writeASCII, this may be problematic if someone use qrencode as a library. Let's just ignore it in ASCII/ANSI mode instead.
22b6819
to
461d4e8
Compare
Increase the size passed to strncat(3) by 1 to silence gcc warning.
The increased value is accounted for the NULL terminator.
This change won't change anything at runtime since strncat(3) will
append that '\0' if size of dst is reached but '\0' is not found.