mardi 27 décembre 2022

Issue building a char from sting and variables

I'm trying to build a string or character to send to a function.

error:

In member function 'void RTSSHOW::RTS_Init()':
Marlin/src/lcd/e3v2/creality/LCD_RTS.cpp:383:37: warning: '%f' directive writing between 3 and 317 bytes into a region of size 0 [-Wformat-overflow=]
  383 |         sprintf_P((char*)mstr, PSTR("%s %f"), mstr, z_values[x][y] * 1000);

Short code summary:

auto mstr = (char*)""; // here is the string I'm trying to build

sprintf_P((char*)mstr, PSTR("%s %f"), mstr, z_values[x][y] * 1000);

sprintf_P((char*)mstr, PSTR("%s %s"), mstr, "\n");

RTS_SndData((char*)mstr, AUTO_BED_LEVEL_MESH_VP);

here is my code pastebin: https://pastebin.com/xrk2GJsh

I'm not fluent in C++ and building a string is not the same as in PHP which I am used to.

I've tried various string and char declarations, but cannot seem to get it.

Aucun commentaire:

Enregistrer un commentaire