fix: correct use of snprintf and strtok

This commit is contained in:
Jaromil
2025-10-06 22:32:36 +02:00
parent 62dd46650c
commit f11132bb4b
3 changed files with 18 additions and 20 deletions

View File

@@ -569,11 +569,11 @@ int tokenise(char *string, const char *delimiter, char ***tokens)
int count = 0;
char *input = strdup(string);
char *result = NULL;
result = strtok(input, delimiter);
result = strtok_r(string, delimiter, &input);
while (result != NULL) {
*tokens = realloc(*tokens, (count + 1) * sizeof(char *));
(*tokens)[count++] = strdup(result);
result = strtok(NULL, delimiter);
result = strtok_r(NULL, delimiter, &input);
}
free(input);
return count;

View File

@@ -38,7 +38,7 @@ Copyright (C) 2010 Marko Cebokli http://lea.hamradio.si/~s57uuu
double PI=3.14159265358979;
//---------------------------------------------------------------
void draw_rectangle(float_rgba *s, int w, int h, float x, float y, float wr, float hr, float_rgba c)
static inline void draw_rectangle(float_rgba *s, int w, int h, float x, float y, float wr, float hr, float_rgba c)
{
int i,j;
int zx,kx,zy,ky;
@@ -139,7 +139,7 @@ draw_rectangle(s, w, h, x1, y1+1, v, 1, black);
//justified
//p=0 one decimal place p=1 three decimal places
//m=1 always show sign
void forstr(float a, int p, int m, char *s)
inline static void forstr(float a, int p, int m, char *s)
{
float b;
char *p3=" %5.3f";
@@ -192,14 +192,14 @@ if (mm==1)
forstr(s.rms,1-u,0,rs);
forstr(s.min,1-u,m,ns);
forstr(s.max,1-u,m,xs);
sprintf(fs,"%s%s%s %s%s", lab, as, rs, ns, xs);
snprintf(fs,255,"%s%s%s %s%s", lab, as, rs, ns, xs);
sprintf(str,fs,s.avg,s.rms,s.min,s.max);
}
else
{
forstr(s.avg,1-u,m,as);
forstr(s.rms,1-u,0,rs);
sprintf(fs,"%s%s%s", lab, as, rs);
snprintf(fs,255,"%s%s%s", lab, as, rs);
sprintf(str,fs,s.avg,s.rms);
}
}
@@ -745,4 +745,3 @@ crosshair(in->sl, in->w, in->h, in->x, in->y, 2*in->sx+1, 2*in->sy+1, 15);
floatrgba2color(in->sl, outframe, in->w , in->h);
}

View File

@@ -114,7 +114,7 @@ while (c[i]!=0)
//justified
//p=0 one decimal place p=1 three decimal places
//m=1 always show sign
void forstr(float a, int p, int m, char *s)
inline static void forstr(float a, int p, int m, char *s)
{
float b;
char *p3=" %5.3f";
@@ -320,7 +320,7 @@ if ((dit&0x00000001)!=0) //marker 1 value
if (m1>0)
{
forstr(data[0],1-u,0,frs);
sprintf(fs,"%%s Mk1=%s", frs);
snprintf(fs,255,"%%s Mk1=%s", frs);
sprintf(str,fs,str,data[0]);
}
else
@@ -331,7 +331,7 @@ if ((dit&0x00000004)!=0) //marker 2 value
if (m2>0)
{
forstr(data[1],1-u,0,frs);
sprintf(fs,"%%s Mk2=%s", frs);
snprintf(fs,255,"%%s Mk2=%s", frs);
sprintf(str,fs,str,data[1]);
}
else
@@ -342,7 +342,7 @@ if ((dit&0x00000010)!=0) //difference marker2-marker1
if ((m2>0)&&(m1>0))
{
forstr(data[2],1-u,0,frs);
sprintf(fs,"%%s D=%s", frs);
snprintf(fs,255,"%%s D=%s", frs);
sprintf(str,fs,str,data[2]);
}
else
@@ -351,25 +351,25 @@ if ((dit&0x00000010)!=0) //difference marker2-marker1
if ((dit&0x00000020)!=0) //average of profile
{
forstr(data[3],1-u,0,frs);
sprintf(fs,"%%s Avg=%s", frs);
snprintf(fs,255,"%%s Avg=%s", frs);
sprintf(str,fs,str,data[3]);
}
if ((dit&0x00000040)!=0) //RMS of profile
{
forstr(data[4],1-u,0,frs);
sprintf(fs,"%%s RMS=%s", frs);
snprintf(fs,255,"%%s RMS=%s", frs);
sprintf(str,fs,str,data[4]);
}
if ((dit&0x00000080)!=0) //MIN of profile
{
forstr(data[5],1-u,0,frs);
sprintf(fs,"%%s Min=%s", frs);
snprintf(fs,255,"%%s Min=%s", frs);
sprintf(str,fs,str,data[5]);
}
if ((dit&0x00000100)!=0) //MAX of profile
{
forstr(data[6],1-u,0,frs);
sprintf(fs,"%%s Max=%s", frs);
snprintf(fs,255,"%%s Max=%s", frs);
sprintf(str,fs,str,data[6]);
}
}
@@ -1035,4 +1035,3 @@ prof(in->sl, in->w, in->h, &in->poz, in->x, in->y, in->tilt, in->len, 1, in->mer
floatrgba2color(in->sl, outframe, in->w , in->h);
}