-
Notifications
You must be signed in to change notification settings - Fork 33
Fixed compile error on latest GCC (14.2.1) #75
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
Conversation
This was caused by the compiler not being able to reason about the bounds check done to make sure that the command size was never over the size of the buffer. This change separates out the checks into separate variables
|
it's interesting that the modified version doesn't trigger the same warning, since there's no more information there. |
|
Hmm, it's interesting that the problem seems intermittent, and seems to be very version-dependent. I remember solving a similar type of issue in #65, just in a different place, so something as simple as separating out the variable name fixes it. I'm using GCC Perhaps it would be worth looking at multiple callsites for |
|
I'm using Ubuntu 22.04.2 LTS and gcc version 11.4.0 and do not see any warnings. |
|
Apologies for the late reply. Since these errors have come and gone based on compiler versions, the fact that there are no warnings for you seems very likely. Since the warning option
Also, the warning specifically seems to find issue with the fact that return values from
int cmd_size = strlen(a) + strlen(b);
if (cmd_size > sizeof(buffer)) {
exit(1);
}
snprintf(buffer, sizeof(buffer), "%s%s", a, b);
if (snprintf(buffer, sizeof(buffer), "%s%s", a, b)) >= sizeof(buffer)) {
exit(1)
}
These are just the options that came to mind, but there likely are better options to fix this issue for good |
|
3 isn't too attractive because it might eliminate also accurate warnings. |
|
I just want to point out that 2 might be a a better option than it appears, because GCC says that it will display the warning when:
Since 2 does use the return value, this would actually remove this category of errors. But completely up to you! |
|
ah -- thanks for pointing that out. |
|
From what I've read, I think that would work to catch formatting errors (negative return value), but I think I will draft up another PR to add the checks to this, if solution (2) sounds like the best one |
|
Continued and rewritten in #76 |
|
@nimble-code Hey I am facing similar issue how can I resolve it.I cloned the repo and followed the instruction of building but then suddently I faced this error |
|
@nimble-code from |
|
once the update to version 5.0 is complete this issue will also disappear |
Hii may I know when can we expect the next version any aprox time.I am trying to implement COBRA in one of my project so a bit of enthusiasm. |
|
it's there now
…On Wed, Mar 19, 2025 at 12:31 PM Pranith_1604 ***@***.***> wrote:
once the update to version 5.0 is complete this issue will also disappear
Hii may I know when can we expect the next version any aprox time.I am
trying to implement COBRA in one of my project so a bit of enthusiasm.
—
Reply to this email directly, view it on GitHub
<#75 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AK6L6IIUPEWJWCXA6OV23GD2VHAZTAVCNFSM6AAAAABRH7SL62VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZXHAZDOOJZHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
[image: Beeram12]*Beeram12* left a comment (nimble-code/Cobra#75)
<#75 (comment)>
once the update to version 5.0 is complete this issue will also disappear
Hii may I know when can we expect the next version any aprox time.I am
trying to implement COBRA in one of my project so a bit of enthusiasm.
—
Reply to this email directly, view it on GitHub
<#75 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AK6L6IIUPEWJWCXA6OV23GD2VHAZTAVCNFSM6AAAAABRH7SL62VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZXHAZDOOJZHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|

This PR contains a fix for a compile error that I noticed while compiling Cobra on my Linux machine:
It appears that in the
dogrepfunction, the compiler cannot adequately reason about the bounds check that we make to make sure that the resulting command that will be run through grep will not overflow the buffer that was created for it.This PR separates those steps out into separate variables, and includes a minor refactor to re-copy the grep command into the buffer, instead of modifying the 5th and 6th indexes of the string to remove a flag before it is run again. This I thought made the intent of the code more readable, at the cost of an additional
snprintf.System Details
gcc --version