Skip to content

Fix: do not crash on ASCII chars with a numeric value exceeding 127. #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

aentinger
Copy link
Contributor

When writing a text this library supports 255 different characters. However, due to the function signature of ArduinoGraphics::text(const char* str, ... which passes a const char* value is interpreted as a negative value when a ASCII character with a numeric value exceeding 127 is passed to this function. Subsequently this leads to an array out-of-bounds access and a application crash.

By casting to uint8_t we ensure that we obtain the correct (positive) numeric value for subsequently accessing the bitmap without array-out-of-bounds access.

Minimal failing test application (crashes upon execution):

#include "ArduinoGraphics.h"
#include "Arduino_LED_Matrix.h"

ArduinoLEDMatrix matrix;

void setup()
{
  matrix.begin();

  float const temperature = 25.3f;
  float const humidity = 47.6f;
  float const pressure = 1.23f;

  char msg[64] = {0};
  snprintf(msg, sizeof(msg), "%0.1f °C, %0.1f %%, %0.2f atm", temperature, humidity, pressure);

  matrix.beginDraw();

  matrix.stroke(0xFFFFFFFF);
  matrix.textScrollSpeed(80);

  matrix.textFont(Font_5x7);
  matrix.beginText(0, 1, 0xFFFFFF);
  matrix.println(msg);
  matrix.endText(SCROLL_LEFT);

  matrix.endDraw();
}

@aentinger aentinger added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Feb 22, 2024
@aentinger aentinger self-assigned this Feb 22, 2024
Copy link

Memory usage change @ 6cafff9

Board flash % RAM for global variables %
arduino:samd:arduino_zero_edbg 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:mkrzero 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/ASCIIDraw
flash
% examples/ASCIIDraw
RAM for global variables
%
arduino:samd:arduino_zero_edbg 0 0.0 0 0.0
arduino:samd:mkrzero 0 0.0 0 0.0
arduino:samd:nano_33_iot 0 0.0 0 0.0
Click for full report CSV
Board,examples/ASCIIDraw<br>flash,%,examples/ASCIIDraw<br>RAM for global variables,%
arduino:samd:arduino_zero_edbg,0,0.0,0,0.0
arduino:samd:mkrzero,0,0.0,0,0.0
arduino:samd:nano_33_iot,0,0.0,0,0.0

@aentinger
Copy link
Contributor Author

output.mp4

@aentinger aentinger merged commit 72388e2 into master Feb 22, 2024
@aentinger aentinger deleted the fix-ascii-greater-127 branch February 22, 2024 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant