Code: Select all
/*
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
void app_main(void)
{
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
uint32_t flash_size;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), WiFi%s%s, ",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
unsigned major_rev = chip_info.revision / 100;
unsigned minor_rev = chip_info.revision % 100;
printf("silicon revision v%d.%d, ", major_rev, minor_rev);
if (esp_flash_get_size(NULL, &flash_size) != ESP_OK)
{
printf("Get flash size failed");
return;
}
printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
printf("esp_get_free_heap_size: %" PRIu32 " bytes\n", esp_get_free_heap_size());
size_t size_to_allocate_1kb = 1000;
uint8_t *ptr1;
uint8_t *ptr2;
ptr1 = malloc(size_to_allocate_1kb * sizeof(*ptr1));
*(ptr1 + 5) = 555;
printf("Minimum free heap size after allocating: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
printf("esp_get_free_heap_size after allocating: %" PRIu32 " bytes\n", esp_get_free_heap_size());
ptr2 = malloc(size_to_allocate_1kb * sizeof(*ptr2));
printf("Minimum free heap size after allocating2: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
printf("esp_get_free_heap_size after allocating2: %" PRIu32 " bytes\n", esp_get_free_heap_size());
}
We are using SonarLint extension for VSCode to give us some guidelines for writing a decent code. I have noticed that even with the
most basic sample, I am getting 10 Problems:
Code: Select all
[{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "C/C++: IntelliSense",
"code": "1696",
"severity": 8,
"message": "#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\\Users\\petrikas.lu\\Desktop\\WORK\\gitchangelog-test\\my_project\\main\\hello_world_main.c).",
"source": "C/C++",
"startLineNumber": 10,
"startColumn": 1,
"endLineNumber": 10,
"endColumn": 31
},{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "C/C++: IntelliSense",
"code": "1696",
"severity": 8,
"message": "cannot open source file \"freertos/FreeRTOS.h\"",
"source": "C/C++",
"startLineNumber": 10,
"startColumn": 1,
"endLineNumber": 10,
"endColumn": 31
},{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "C/C++: IntelliSense",
"code": "1696",
"severity": 8,
"message": "cannot open source file \"freertos/task.h\"",
"source": "C/C++",
"startLineNumber": 11,
"startColumn": 1,
"endLineNumber": 11,
"endColumn": 27
},{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "C/C++: IntelliSense",
"code": "1696",
"severity": 8,
"message": "cannot open source file \"esp_chip_info.h\"",
"source": "C/C++",
"startLineNumber": 12,
"startColumn": 1,
"endLineNumber": 12,
"endColumn": 27
},{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "C/C++: IntelliSense",
"code": "1696",
"severity": 8,
"message": "cannot open source file \"esp_flash.h\"",
"source": "C/C++",
"startLineNumber": 13,
"startColumn": 1,
"endLineNumber": 13,
"endColumn": 23
},{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "sonarlint",
"code": "c:S5350",
"severity": 4,
"message": "Make the type of this variable a pointer-to-const. The current type of \"ptr2\" is \"unsigned char *\".",
"source": "sonarlint",
"startLineNumber": 47,
"startColumn": 5,
"endLineNumber": 47,
"endColumn": 18
},{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "sonarlint",
"code": "c:S5276",
"severity": 4,
"message": "implicit conversion from 'int' to 'uint8_t' (aka 'unsigned char') changes value from 555 to 43",
"source": "sonarlint",
"startLineNumber": 50,
"startColumn": 19,
"endLineNumber": 50,
"endColumn": 22
},{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "sonarlint",
"code": "c:S3584",
"severity": 4,
"message": "Potential leak of memory pointed to by 'ptr1' [+10 locations]",
"source": "sonarlint",
"startLineNumber": 51,
"startColumn": 76,
"endLineNumber": 51,
"endColumn": 108
},{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "sonarlint",
"code": "c:S1854",
"severity": 4,
"message": "Value stored to 'ptr2' is never read",
"source": "sonarlint",
"startLineNumber": 54,
"startColumn": 5,
"endLineNumber": 54,
"endColumn": 9
},{
"resource": "/c:/Users/petrikas.lu/Desktop/WORK/gitchangelog-test/my_project/main/hello_world_main.c",
"owner": "sonarlint",
"code": "c:S3584",
"severity": 4,
"message": "Potential leak of memory pointed to by 'ptr2' [+10 locations]",
"source": "sonarlint",
"startLineNumber": 55,
"startColumn": 77,
"endLineNumber": 55,
"endColumn": 109
}]
Does anyone else use SonarLint and know what could be the problems? Can you recommend a way to solve them or recommend another linter?