• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-mcu / 1510560513

24 Oct 2024 12:04PM UTC coverage: 2.013% (+0.007%) from 2.006%
1510560513

push

gitlab-ci

lluiscampos
chore: Move variable declaration so that its always initialized at END

Clears `clang` warning:
```
.../mender-api.c:250:9: error: variable 'provides' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
  250 |     if (NULL == cJSON_AddStringToObject(json_provides, "device_type", mender_api_config.device_type)) {
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/llvm-18/lib/clang/18/include/__stddef_null.h:26:14: note: expanded from macro 'NULL'
   26 | #define NULL ((void*)0)
      |              ^
.../mender-api.c:302:35: note: uninitialized use occurs here
  302 |     mender_utils_free_linked_list(provides);
      |                                   ^~~~~~~~
.../mender-api.c:250:5: note: remove the 'if' if its condition is always false
  250 |     if (NULL == cJSON_AddStringToObject(json_provides, "device_type", mender_api_config.device_type)) {
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251 |         mender_log_error("Unable to allocate memory");
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  252 |         goto END;
      |         ~~~~~~~~~
  253 |     }
      |     ~

```

Signed-off-by: Lluis Campos <lluis.campos@northern.tech>

31 of 1540 relevant lines covered (2.01%)

0.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/core/src/mender-artifact-download.c
1
/**
2
 * @file      mender-artifact-download.c
3
 * @brief     Mender artifact download implementation
4
 *
5
 * Copyright joelguittet and mender-mcu-client contributors
6
 * Copyright Northern.tech AS
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
#include "mender-api.h"
22
#include "mender-artifact.h"
23
#include "mender-artifact-download.h"
24
#include "mender-artifact-download-data.h"
25
#include "mender-http.h"
26
#include "mender-log.h"
27

28
static mender_err_t mender_download_artifact_callback(mender_http_client_event_t       event,
29
                                                      void                            *data,
30
                                                      size_t                           data_length,
31
                                                      mender_artifact_download_data_t *dl_data);
32

33
mender_err_t
34
mender_download_artifact(const char *uri, mender_deployment_data_t *deployment_data, mender_update_module_t **update_module) {
×
35
    assert(NULL != uri);
×
36
    assert(NULL != deployment_data);
×
37
    assert(NULL != update_module);
×
38

39
    mender_err_t ret;
40
    int          status = 0;
×
41

42
    mender_artifact_download_data_t dl_data = {
×
43
        .deployment                 = deployment_data,
44
        .artifact_download_callback = &mender_download_artifact_callback,
45
        .ret                        = MENDER_OK,
46
    };
47

48
    /* Perform HTTP request */
49
    if (MENDER_OK != (ret = mender_http_artifact_download(uri, &dl_data, &status))) {
×
50
        mender_log_error("Unable to perform HTTP request");
×
51
        return ret;
×
52
    }
53

54
    /* Treatment depending of the status */
55
    if (200 == status) {
×
56
        /* Nothing to do */
57
        *update_module = dl_data.update_module;
×
58
        return MENDER_OK;
×
59
    } else {
60
        mender_api_print_response_error(NULL, status);
×
61
        return MENDER_FAIL;
×
62
    }
63
}
64

65
static mender_err_t
66
mender_download_artifact_callback(mender_http_client_event_t event, void *data, size_t data_length, mender_artifact_download_data_t *dl_data) {
×
67
    mender_err_t ret = MENDER_OK;
×
68

69
    mender_artifact_ctx_t *mender_artifact_ctx = NULL;
×
70

71
    /* Treatment depending of the event */
72
    switch (event) {
×
73
        case MENDER_HTTP_EVENT_CONNECTED:
×
74
            /* Create new artifact context */
75
            if (NULL == (mender_artifact_ctx = mender_artifact_create_ctx(2 * MENDER_ARTIFACT_STREAM_BLOCK_SIZE + mender_http_recv_buf_length))) {
×
76
                mender_log_error("Unable to create artifact context");
×
77
                return MENDER_FAIL;
×
78
            }
79
            break;
×
80
        case MENDER_HTTP_EVENT_DATA_RECEIVED:
×
81
            /* Check input data */
82
            if ((NULL == data) || (0 == data_length)) {
×
83
                mender_log_error("Invalid data received");
×
84
                return MENDER_FAIL;
×
85
            }
86

87
            /* Check artifact context */
88
            if (MENDER_OK != mender_artifact_get_ctx(&mender_artifact_ctx)) {
×
89
                mender_log_error("Unable to get artifact context");
×
90
                return MENDER_FAIL;
×
91
            }
92
            assert(NULL != mender_artifact_ctx);
×
93

94
            /* Parse input data */
95
            if (MENDER_OK != (ret = mender_artifact_process_data(mender_artifact_ctx, data, data_length, dl_data))) {
×
96
                mender_log_error("Unable to process data");
×
97
                return ret;
×
98
            }
99
            break;
×
100
        case MENDER_HTTP_EVENT_DISCONNECTED:
×
101
            break;
×
102
        case MENDER_HTTP_EVENT_ERROR:
×
103
            /* Downloading the artifact fails */
104
            mender_log_error("An error occurred");
×
105
            return MENDER_FAIL;
×
106
        default:
×
107
            /* Should not occur */
108
            return MENDER_FAIL;
×
109
    }
110

111
    return ret;
×
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc