aboutsummaryrefslogtreecommitdiff
path: root/src/cRender.cpp
diff options
context:
space:
mode:
authorGravatar jonas <himself@jonasgunz.de> 2019-03-28 10:21:23 +0100
committerGravatar jonas <himself@jonasgunz.de> 2019-03-28 10:21:23 +0100
commit4bebc71c013b4874c699f987e42098e9c0450990 (patch)
tree31eebad6f5fd18cc6fbdbccd98a324fd1c3be6f0 /src/cRender.cpp
parentd04b07d33eefb6410550b6b98a6f1dbf61e4d3dd (diff)
downloadtermgl-4bebc71c013b4874c699f987e42098e9c0450990.tar.gz
replaced sprintf with snprintf #8
Diffstat (limited to 'src/cRender.cpp')
-rw-r--r--src/cRender.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/cRender.cpp b/src/cRender.cpp
index 2035b21..5e7677f 100644
--- a/src/cRender.cpp
+++ b/src/cRender.cpp
@@ -213,31 +213,34 @@ int cRender::render(void)
#elif __linux__
- char buffer[40];
- char colorstr[30];
+ const unsigned int buffer_len = 40;
+ const unsigned int colorstr_len = 30;
+
+ char buffer[ buffer_len ];
+ char colorstr[ colorstr_len ];
+
uint8_t color[3] = {(uint8_t) (0x0000ff & wColor[o][i]), //Color
(uint8_t)((0x00ff00 & wColor[o][i]) >> 8), //Background
(uint8_t)((0xff0000 & wColor[o][i]) >> 16)};//Modifier
{////
int cc = 0;
- cc = cc + sprintf(&colorstr[cc], "%u", color[0]);
+ cc = cc + snprintf(&colorstr[cc], colorstr_len - cc - 1, "%u", color[0]);
if(color[1])
{
colorstr[cc] = ';';
colorstr[cc + 1] = color[1];
- cc += 1 + sprintf(&colorstr[cc + 1], "%u", color[1]);
+ cc += 1 + snprintf(&colorstr[cc + 1],colorstr_len - cc - 1, "%u", color[1]);
}
if(color[2])
{
colorstr[cc] = ';';
- cc += 1 + sprintf(&colorstr[cc + 1], "%u", color[2]);
+ cc += 1 + snprintf(&colorstr[cc + 1], colorstr_len - cc - 1, "%u", color[2]);
}
}////
- int cbuf = sprintf(buffer,"\e[%u;%uH\e[%sm%c\e[0m", i + 1, o + 1, colorstr, cScreen[o][i]);
+ int cbuf = snprintf(buffer, buffer_len - 1,"\e[%u;%uH\e[%sm%c\e[0m", i + 1, o + 1, colorstr, cScreen[o][i]);
// Position Color Origin is at 1,1
- //int cbuf = sprintf(buffer,"\e[%u;%uH%c", i + 1, o + 1, cScreen[o][i]);
if(!bMute)
write (STDOUT_FILENO, buffer, cbuf);
@@ -447,12 +450,13 @@ void cRender::printDebugInfo()
if(!bPrintDebugInfo)
return;
- char dbgtxt[30];
+ const unsigned int dbgtxt_len = 30;
+ char dbgtxt[ dbgtxt_len ];
double lrt = (double)lastFrameTime / CLOCKS_PER_SEC;
double fps = getFrametime() ? 1/getFrametime() : 0;
- sprintf(dbgtxt, "R: %f F: %f ", lrt, fps);
+ snprintf(dbgtxt, dbgtxt_len - 1, "R: %f F: %f ", lrt, fps);
drawText(dbgtxt, {0,0}, _COL_BLACK | _COL_WHITE_BG);
}