azure-sdk-for-c icon indicating copy to clipboard operation
azure-sdk-for-c copied to clipboard

We need a linter for C code

Open antkmsft opened this issue 5 years ago • 7 comments

These things should not be possible:

az_curl_done(CURL ** pp);
...
CURL * p_curl;
az_curl_done(p_curl); // <-- does compile

or

do_something(uint8_t const * x);
...
az_span span = (az_span){ .begin = ..., .size = ... };
do_something(span); // happy debugging!

@sergey-shandar suggested to assign this to you @barcharcraz, so that maybe you can rescommend us something we should use.

antkmsft avatar Nov 05 '19 22:11 antkmsft

I can't get the second example to compile.

void do_something(uint8_t const *test)
{
    (void)test;
}
typedef struct az_span
{
    int size;
    uint8_t *data;
} az_span;
int main()
{
    az_span span = (az_span){.size = 8, .data = 0};
    do_something(span);
}

barcharcraz avatar Nov 08 '19 23:11 barcharcraz

Ah I see what's going on now.

CURL is:

typedef void CURL;

so the first example is:

az_curl_done(void** pp);

void* p_curl;
az_curl_done(p_curl); <- implicit conversion here

barcharcraz avatar Nov 08 '19 23:11 barcharcraz

for curl in particular it looks like there's a macro CURL_STRICTER that, when defined, gives a better typedef here, and would prevent this problem. Shame there's no easy way to find out about it by reading the user-facing docs.

barcharcraz avatar Nov 08 '19 23:11 barcharcraz

Any concern with using clang-tidy?

joshfree avatar Nov 21 '19 15:11 joshfree

@joshfree I'm ok with anything if it solves such problems and not introducing more problems :-)

sergey-shandar avatar Nov 22 '19 18:11 sergey-shandar

I think @ahsonkhan did something about adding Lint... Can you confirm Ahson? Can we close this then?

vhvb1989 avatar Sep 28 '20 23:09 vhvb1989

I ran the linter across our repo before GA, yes, but we should leave this issue open until that has been added to CI for automated checks.

ahsonkhan avatar Sep 30 '20 20:09 ahsonkhan

Hi @antkmsft, we deeply appreciate your input into this project. Regrettably, this issue has remained inactive for over 2 years, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support.

github-actions[bot] avatar Mar 15 '24 18:03 github-actions[bot]