Giter Site home page Giter Site logo

Code Inspect Error about platformio-core HOT 3 CLOSED

rvxfahim avatar rvxfahim commented on June 19, 2024
Code Inspect Error

from platformio-core.

Comments (3)

valeros avatar valeros commented on June 19, 2024

Hi @rvxfahim, your code snippet is not enough to evaluate the correctness of the reported defect. Please attach here a minimal PlatformIO project to reproduce the issue.

from platformio-core.

rvxfahim avatar rvxfahim commented on June 19, 2024

Hi @rvxfahim, your code snippet is not enough to evaluate the correctness of the reported defect. Please attach here a minimal PlatformIO project to reproduce the issue.

Hi, the code is very big, but the following part is the callback function for a ble characterisitics where this variable is being flagged by the static analysis.

uint8_t ip[4] = {192, 168, 31, 4};
void BLEipCallBack::onWrite(BLECharacteristic *pCharacteristic)
{
std::string value = pCharacteristic->getValue();
// parse the string to get the IP address
// the string is in the format "xxx.xxx.xxx.xxx"
// where x is a number
// the IP address is stored in the global variable ip
ip[4] = {0};
int segmentIndex = 0;
std::string segment = "";
for (char c : value)
{
if (c == '.')
{
ip[segmentIndex] = std::stoi(segment);
segmentIndex++;
segment = "";
}
else
{
segment += c;
}
}
// handle the last segment
ip[segmentIndex] = std::stoi(segment);
// store the blob
NVS.setBlob("ip", ip, sizeof(ip));
// set the IP address
server[0] = ip[0];
server[1] = ip[1];
server[2] = ip[2];
server[3] = ip[3];
nh.getHardware()->setConnection(server, serverPort);
Serial.println("IP address changed to:");
Serial.print(ip[0]);
Serial.print(".");
Serial.print(ip[1]);
Serial.print(".");
Serial.print(ip[2]);
Serial.print(".");
Serial.println(ip[3]);
}

from platformio-core.

valeros avatar valeros commented on June 19, 2024

You've declared an array of size 4, the array indexing in C/C++ starts from 0, so the lowest index is 0 and the highest index is 3. Executing ip[4] is an "index out of bounds error" which is correctly reported by Cppcheck.

from platformio-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.