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

20
#include "mender-log.h"
21
#include "mender-update-module.h"
22

23
/**
24
 * @brief Mender update modules list
25
 */
26
static mender_update_module_t **update_modules_list  = NULL;
27
static size_t                   update_modules_count = 0;
28

29
mender_err_t
30
mender_update_module_register(mender_update_module_t *update_module) {
×
31
    assert(NULL != update_module);
×
32

33
    mender_update_module_t **tmp;
34
    mender_err_t             ret = MENDER_OK;
×
35

36
    for (size_t i = 0; i < update_modules_count; i++) {
×
37
        if (StringEqual(update_module->artifact_type, update_modules_list[i]->artifact_type)) {
×
38
            mender_log_error("Not registering another update module for artifact type: %s", update_module->artifact_type);
×
39
            return MENDER_FAIL;
×
40
        }
41
    }
42

43
    /* Add mender artifact type to the list */
44
    if (NULL == (tmp = (mender_update_module_t **)realloc(update_modules_list, (update_modules_count + 1) * sizeof(mender_update_module_t *)))) {
×
45
        mender_log_error("Unable to allocate memory for update modules list");
×
46
        ret = MENDER_FAIL;
×
47
        goto END;
×
48
    }
49
    update_modules_list                         = tmp;
×
50
    update_modules_list[update_modules_count++] = update_module;
×
51
    ret                                         = MENDER_OK;
×
52

53
END:
×
54

55
    return ret;
×
56
}
57

58
void
59
mender_update_module_unregister_all(void) {
×
60
    if (NULL != update_modules_list) {
×
61
        for (size_t update_module_index = 0; update_module_index < update_modules_count; update_module_index++) {
×
62
            free(update_modules_list[update_module_index]);
×
63
        }
64
        FREE_AND_NULL(update_modules_list);
×
65
    }
66
    update_modules_count = 0;
×
67
}
×
68

69
mender_update_module_t *
70
mender_update_module_get(const char *artifact_type) {
×
71
    mender_update_module_t *ret = NULL;
×
72

73
    /* Treatment depending of the type */
74
    if (NULL != update_modules_list) {
×
75
        for (size_t update_module_index = 0; (NULL == ret) && (update_module_index < update_modules_count); update_module_index++) {
×
76
            /* Check artifact type */
77
            if (StringEqual(artifact_type, update_modules_list[update_module_index]->artifact_type)) {
×
78
                ret = update_modules_list[update_module_index];
×
79
            }
80
        }
81
    }
82

83
    return ret;
×
84
}
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