File: libcurl.c

package info (click to toggle)
cppcheck 2.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,688 kB
  • sloc: cpp: 272,455; python: 22,408; ansic: 8,088; sh: 1,059; makefile: 1,041; xml: 987; cs: 291
file content (90 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90

// Test library configuration for libcurl.cfg
//
// Usage:
// $ cppcheck --check-library --library=libcurl --enable=style,information --inconclusive --error-exitcode=1 --inline-suppr test/cfg/libcurl.c
// =>
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//

// cppcheck-suppress-file valueFlowBailout

#include <curl/curl.h>
#include <stdio.h>

void validCode()
{
    CURL *curl = curl_easy_init();
    if (curl) {
        CURLcode res;
        // cppcheck-suppress valueFlowBailoutIncompleteVar
        curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
        res = curl_easy_perform(curl);
        if (res != CURLE_OK) {
            printf("error");
        } else {
            long response_code;
            curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
            printf("%ld", response_code);
            char * pStr = curl_easy_escape(curl, "a", 1);
            if (pStr)
                printf("%s", pStr);
            curl_free(pStr);
            curl_easy_reset(curl);
        }
        curl_easy_cleanup(curl);
    }
}

// cppcheck-suppress constParameterPointer
void ignoredReturnValue(CURL * handle)
{
    // cppcheck-suppress ignoredReturnValue
    curl_easy_strerror(1);
}

void resourceLeak_curl_easy_init()
{
    const CURL *curl = curl_easy_init();
    printf("%p", curl);
    // cppcheck-suppress resourceLeak
}

void resourceLeak_curl_easy_duphandle(CURL * handle)
{
    const CURL *curl = curl_easy_duphandle(handle);
    printf("%p", curl);
    // cppcheck-suppress resourceLeak
}

void memleak_curl_easy_escape(CURL * handle)
{
    const char * pStr = curl_easy_escape(handle, "a", 1);
    if (pStr)
        printf("%s", pStr);
    // cppcheck-suppress memleak
}

void nullPointer(CURL * handle)
{
    char * buf[10] = {0};
    size_t len;

    curl_easy_recv(handle, buf, 10, &len);
    // cppcheck-suppress nullPointer
    curl_easy_recv(handle, buf, 10, NULL);
    curl_easy_send(handle, buf, 10, &len);
    // cppcheck-suppress nullPointer
    curl_easy_send(handle, buf, 10, NULL);
}

void uninitvar(CURL * handle)
{
    const char * bufInit[10] = {0};
    const char * bufUninit;
    size_t len;

    curl_easy_send(handle, bufInit, 10, &len);
    // cppcheck-suppress uninitvar
    curl_easy_send(handle, bufUninit, 10, &len);
}