-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
pass a char buffer to simplecpp instead of a stream #6379
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
7b20b6d
to
a67a83d
Compare
The callgrind CI job shows a small reduction in Ir: |
0085e46
to
cb2981d
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
10eaa80
to
0b40ad2
Compare
This comment was marked as outdated.
This comment was marked as outdated.
2e85422
to
df92530
Compare
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.
I like the interface that we pass the istream to simplecpp. it makes the interface more strict. a const char* parameter can be a filename, code, configuration, etc.
democlient/democlient.cpp
Outdated
cppcheck.check(FileWithDetails("test.cpp"), code); | ||
template<std::size_t size> | ||
void run(const char (&code)[size]) { | ||
cppcheck.check(FileWithDetails("test.cpp"), reinterpret_cast<const uint8_t*>(code), size-1); |
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.
the buffer that we pass to this function is always 4000 bytes right? But the actual code is much shorter typically. I think it would make sense to pass only the data until the terminating zero to simplecpp.
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.
Yes, that definitely felt off when I took a final look before I made it ready for review.
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.
This actually changes the behavior since before it was doing implicitly doing strlen()
on the input and now we provide a fixed size.
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.
Fixed.
lib/cppcheck.cpp
Outdated
@@ -562,10 +562,9 @@ unsigned int CppCheck::check(const FileWithDetails &file) | |||
return checkFile(file, emptyString); | |||
} | |||
|
|||
unsigned int CppCheck::check(const FileWithDetails &file, const std::string &content) | |||
unsigned int CppCheck::check(const FileWithDetails &file, const uint8_t* data, std::size_t size) |
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.
I feel that this interface is less safe.
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.
We could keep the std::string
version for convenience. I got rid of it to make sure we always specify a buffer and because it was unused now.
Please let's take that with a grain of salt. It's the instruction count not a time estimate. |
some kind of small benchmark that measures actual time would be interesting. |
I will provide additional values. This will also help with value evaluation stuff which is not executed in that job. I just should it to highlight that it even has a measurable impact without that. |
That just moves the potential mistakes to a different layer. You could still pass unterminated data to the stream or improperly size your buffer. If we were using newer standards we could provide |
Sorry I feel we talk about different things. I talked about type safety and you about bounds safety. So ok we can still have bounds safety problems with the std::istream. But developers sometimes mix up the parameters and with a |
My idea would be to deprecate the raw pointers when you have the later standard wrappers. As I said I will file a ticket about it and try to address it in this dev cycle. I also do not know how many people use the interface since we modified those several times and never get any reports about it so I assume those user might be non-existent. |
You should check the documentation before you use it but point taken. Maybe we could use more descriptive names like I would do the function names in this PR and do the safer interface function in a follow-up since that needs some looking into. |
I did that - please have a look. |
I might also still need to add convenience stream versions to the interface. And we would need tests for that - I am not so sure anymore about adding essentially dead code. |
I just don't like this. A istream parameter is better than 2 |
I will add the other safer versions in this PR as well and try to find a way to opt into the unsafe version so it can still be used internally. |
No description provided.