Replace all sprintf with snprintf
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
134b8b538f
commit
7c37421266
@ -270,22 +270,23 @@ int main(int argc, char *argv[])
|
|||||||
/* 29 bit address */
|
/* 29 bit address */
|
||||||
|
|
||||||
frame.can_id = frame.can_id & ~CAN_EFF_FLAG;
|
frame.can_id = frame.can_id & ~CAN_EFF_FLAG;
|
||||||
sprintf(sbuf, "T%08" PRIx32 "%d",
|
snprintf(sbuf, sizeof(sbuf), "T%08" PRIx32 "%d",
|
||||||
frame.can_id, frame.len);
|
frame.can_id, frame.len);
|
||||||
sbp = &sbuf[10];
|
sbp = &sbuf[10];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* 11 bit address */
|
/* 11 bit address */
|
||||||
|
|
||||||
sprintf(sbuf, "t%03" PRIx32 "%d",
|
snprintf(sbuf, sizeof(sbuf), "t%03" PRIx32 "%d",
|
||||||
frame.can_id, frame.len);
|
frame.can_id, frame.len);
|
||||||
sbp = &sbuf[5];
|
sbp = &sbuf[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < frame.len; i++)
|
for (i = 0; i < frame.len; i++)
|
||||||
{
|
{
|
||||||
sprintf(sbp, "%02X", frame.data[i]);
|
snprintf(sbp, sizeof(sbuf) - (sbp - sbuf),
|
||||||
|
"%02X", frame.data[i]);
|
||||||
sbp += 2;
|
sbp += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ static void el_print_file(const char *workdir)
|
|||||||
|
|
||||||
/* Create full path to log file embedlog will use */
|
/* Create full path to log file embedlog will use */
|
||||||
|
|
||||||
sprintf(log_path, "%s/log-rotate", workdir);
|
snprintf(log_path, sizeof(log_path), "%s/log-rotate", workdir);
|
||||||
|
|
||||||
/* Enable file rotation, maximum 5 files will be created, none of the log
|
/* Enable file rotation, maximum 5 files will be created, none of the log
|
||||||
* files size shall exceed 512 bytes. Rotate size is low to present how
|
* files size shall exceed 512 bytes. Rotate size is low to present how
|
||||||
|
@ -156,13 +156,14 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
/* Save the sector in our array */
|
/* Save the sector in our array */
|
||||||
|
|
||||||
sectors[x] = (uint16_t) logsector;
|
sectors[x] = (uint16_t)logsector;
|
||||||
seqs[x] = seq++;
|
seqs[x] = seq++;
|
||||||
|
|
||||||
/* Now write some data to the sector */
|
/* Now write some data to the sector */
|
||||||
|
|
||||||
sprintf(buffer, "Logical sector %d sequence %d\n",
|
snprintf(buffer, fmt.availbytes,
|
||||||
sectors[x], seqs[x]);
|
"Logical sector %d sequence %d\n",
|
||||||
|
sectors[x], seqs[x]);
|
||||||
|
|
||||||
readwrite.logsector = sectors[x];
|
readwrite.logsector = sectors[x];
|
||||||
readwrite.offset = 0;
|
readwrite.offset = 0;
|
||||||
@ -202,8 +203,9 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
printf("\r%d ", sectors[x]);
|
printf("\r%d ", sectors[x]);
|
||||||
|
|
||||||
sprintf(&buffer[100], "Logical sector %d sequence %d\n",
|
snprintf(&buffer[100], fmt.availbytes - 100,
|
||||||
sectors[x], seqs[x]);
|
"Logical sector %d sequence %d\n",
|
||||||
|
sectors[x], seqs[x]);
|
||||||
|
|
||||||
if (strcmp(buffer, &buffer[100]) != 0)
|
if (strcmp(buffer, &buffer[100]) != 0)
|
||||||
{
|
{
|
||||||
@ -224,8 +226,9 @@ int main(int argc, FAR char *argv[])
|
|||||||
/* Now write over the sector data with new data, causing a relocation.
|
/* Now write over the sector data with new data, causing a relocation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sprintf(buffer, "Logical sector %d sequence %d\n",
|
snprintf(buffer, fmt.availbytes,
|
||||||
sectors[x], seqs[x]);
|
"Logical sector %d sequence %d\n",
|
||||||
|
sectors[x], seqs[x]);
|
||||||
readwrite.logsector = sectors[x];
|
readwrite.logsector = sectors[x];
|
||||||
readwrite.offset = 0;
|
readwrite.offset = 0;
|
||||||
readwrite.count = strlen(buffer) + 1;
|
readwrite.count = strlen(buffer) + 1;
|
||||||
@ -252,7 +255,8 @@ int main(int argc, FAR char *argv[])
|
|||||||
* causing a relocation.
|
* causing a relocation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sprintf(buffer, "Appended data in sector %d\n", sectors[x]);
|
snprintf(buffer, fmt.availbytes,
|
||||||
|
"Appended data in sector %d\n", sectors[x]);
|
||||||
readwrite.logsector = sectors[x];
|
readwrite.logsector = sectors[x];
|
||||||
readwrite.offset = 64;
|
readwrite.offset = 64;
|
||||||
readwrite.count = strlen(buffer) + 1;
|
readwrite.count = strlen(buffer) + 1;
|
||||||
|
@ -50,7 +50,8 @@ int foc_device_init(FAR struct foc_device_s *dev, int id)
|
|||||||
|
|
||||||
/* Get FOC devpath */
|
/* Get FOC devpath */
|
||||||
|
|
||||||
sprintf(devpath, "%s%d", CONFIG_EXAMPLES_FOC_DEVPATH, id);
|
snprintf(devpath, sizeof(devpath), "%s%d",
|
||||||
|
CONFIG_EXAMPLES_FOC_DEVPATH, id);
|
||||||
|
|
||||||
/* Open FOC device */
|
/* Open FOC device */
|
||||||
|
|
||||||
|
@ -887,10 +887,10 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor,
|
|||||||
|
|
||||||
/* Get qenco devpath */
|
/* Get qenco devpath */
|
||||||
|
|
||||||
sprintf(motor->qedpath,
|
snprintf(motor->qedpath, sizeof(motor->qedpath),
|
||||||
"%s%d",
|
"%s%d",
|
||||||
CONFIG_EXAMPLES_FOC_QENCO_DEVPATH,
|
CONFIG_EXAMPLES_FOC_QENCO_DEVPATH,
|
||||||
motor->envp->id);
|
motor->envp->id);
|
||||||
|
|
||||||
/* Configure qenco angle handler */
|
/* Configure qenco angle handler */
|
||||||
|
|
||||||
@ -918,10 +918,10 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor,
|
|||||||
|
|
||||||
/* Get hall devpath */
|
/* Get hall devpath */
|
||||||
|
|
||||||
sprintf(motor->hldpath,
|
snprintf(motor->hldpath, sizeof(motor->hldpath),
|
||||||
"%s%d",
|
"%s%d",
|
||||||
CONFIG_EXAMPLES_FOC_HALL_DEVPATH,
|
CONFIG_EXAMPLES_FOC_HALL_DEVPATH,
|
||||||
motor->envp->id);
|
motor->envp->id);
|
||||||
|
|
||||||
/* Configure hall angle handler */
|
/* Configure hall angle handler */
|
||||||
|
|
||||||
|
@ -871,10 +871,10 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor,
|
|||||||
|
|
||||||
/* Get qenco devpath */
|
/* Get qenco devpath */
|
||||||
|
|
||||||
sprintf(motor->qedpath,
|
snprintf(motor->qedpath, sizeof(motor->qedpath),
|
||||||
"%s%d",
|
"%s%d",
|
||||||
CONFIG_EXAMPLES_FOC_QENCO_DEVPATH,
|
CONFIG_EXAMPLES_FOC_QENCO_DEVPATH,
|
||||||
motor->envp->id);
|
motor->envp->id);
|
||||||
|
|
||||||
/* Configure qenco angle handler */
|
/* Configure qenco angle handler */
|
||||||
|
|
||||||
@ -902,10 +902,10 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor,
|
|||||||
|
|
||||||
/* Get hall devpath */
|
/* Get hall devpath */
|
||||||
|
|
||||||
sprintf(motor->hldpath,
|
snprintf(motor->hldpath, sizeof(motor->hldpath),
|
||||||
"%s%d",
|
"%s%d",
|
||||||
CONFIG_EXAMPLES_FOC_HALL_DEVPATH,
|
CONFIG_EXAMPLES_FOC_HALL_DEVPATH,
|
||||||
motor->envp->id);
|
motor->envp->id);
|
||||||
|
|
||||||
/* Configure hall angle handler */
|
/* Configure hall angle handler */
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ static FAR void *foc_control_thr(FAR void *arg)
|
|||||||
|
|
||||||
/* Get queue name */
|
/* Get queue name */
|
||||||
|
|
||||||
sprintf(mqname, "%s%d", CONTROL_MQ_MQNAME, envp->id);
|
snprintf(mqname, sizeof(mqname), "%s%d", CONTROL_MQ_MQNAME, envp->id);
|
||||||
|
|
||||||
/* Open queue */
|
/* Open queue */
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ int foc_ctrlthr_init(FAR struct foc_ctrl_env_s *foc, int i, FAR mqd_t *mqd,
|
|||||||
|
|
||||||
/* Get queue name */
|
/* Get queue name */
|
||||||
|
|
||||||
sprintf(mqname, "%s%d", CONTROL_MQ_MQNAME, foc->id);
|
snprintf(mqname, sizeof(mqname), "%s%d", CONTROL_MQ_MQNAME, foc->id);
|
||||||
|
|
||||||
/* Initialize thread recv queue */
|
/* Initialize thread recv queue */
|
||||||
|
|
||||||
|
@ -192,8 +192,9 @@ void parse_and_callback(cJSON *item, const char *prefix)
|
|||||||
{
|
{
|
||||||
while (item)
|
while (item)
|
||||||
{
|
{
|
||||||
char *newprefix = malloc(strlen(prefix) + strlen(item->name) + 2);
|
size_t len = strlen(prefix) + strlen(item->name) + 2;
|
||||||
sprintf(newprefix, "%s/%s", prefix, item->name);
|
char *newprefix = malloc(len);
|
||||||
|
snprintf(newprefix, len, "%s/%s", prefix, item->name);
|
||||||
int dorecurse = callback(newprefix, item->type, item);
|
int dorecurse = callback(newprefix, item->type, item);
|
||||||
if (item->child && dorecurse) parse_and_callback(item->child, newprefix);
|
if (item->child && dorecurse) parse_and_callback(item->child, newprefix);
|
||||||
item = item->next;
|
item = item->next;
|
||||||
|
@ -207,7 +207,8 @@ static int download_firmware_image(FAR const char *url)
|
|||||||
|
|
||||||
for (i = 0; i < MD5_DIGEST_LENGTH; i++)
|
for (i = 0; i < MD5_DIGEST_LENGTH; i++)
|
||||||
{
|
{
|
||||||
sprintf(&hash[i * 2], "%02x", digest[i]);
|
snprintf(&hash[i * 2], sizeof(hash) - i * 2,
|
||||||
|
"%02x", digest[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash[MD5_HASH_LENGTH] = '\0';
|
hash[MD5_HASH_LENGTH] = '\0';
|
||||||
|
@ -212,7 +212,8 @@ static void show_directories(const char *path, int indent)
|
|||||||
{
|
{
|
||||||
char *subdir;
|
char *subdir;
|
||||||
printf("%s/\n", direntry->d_name);
|
printf("%s/\n", direntry->d_name);
|
||||||
sprintf(g_namebuffer, "%s/%s", path, direntry->d_name);
|
snprintf(g_namebuffer, sizeof(g_namebuffer),
|
||||||
|
"%s/%s", path, direntry->d_name);
|
||||||
subdir = strdup(g_namebuffer);
|
subdir = strdup(g_namebuffer);
|
||||||
show_directories(subdir, indent + 1);
|
show_directories(subdir, indent + 1);
|
||||||
free(subdir);
|
free(subdir);
|
||||||
|
@ -152,7 +152,7 @@ static int lo_client(void)
|
|||||||
|
|
||||||
for (i = 0; ; i++)
|
for (i = 0; ; i++)
|
||||||
{
|
{
|
||||||
sprintf(outbuf, "Loopback message %d", i);
|
snprintf(outbuf, sizeof(outbuf), "Loopback message %d", i);
|
||||||
len = strlen(outbuf);
|
len = strlen(outbuf);
|
||||||
|
|
||||||
printf("lo_client: Sending '%s' (%d bytes)\n", outbuf, len);
|
printf("lo_client: Sending '%s' (%d bytes)\n", outbuf, len);
|
||||||
|
@ -92,8 +92,9 @@ static char *padstr(char *s, int length)
|
|||||||
static char buf[MAXSTRLEN];
|
static char buf[MAXSTRLEN];
|
||||||
char fmt[10];
|
char fmt[10];
|
||||||
|
|
||||||
sprintf(fmt, (int)strlen(s) > length ? "%%.%ds" : "%%-%ds", length);
|
snprintf(fmt, sizeof(fmt),
|
||||||
sprintf(buf, fmt, s);
|
(int)strlen(s) > length ? "%%.%ds" : "%%-%ds", length);
|
||||||
|
snprintf(buf, sizeof(buf), fmt, s);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@ -206,7 +207,7 @@ static void idle(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tp = localtime(&t);
|
tp = localtime(&t);
|
||||||
sprintf(buf, " %.2d-%.2d-%.4d %.2d:%.2d:%.2d",
|
snprintf(buf, sizeof(buf), " %.2d-%.2d-%.4d %.2d:%.2d:%.2d",
|
||||||
tp->tm_mday, tp->tm_mon + 1, tp->tm_year + 1900,
|
tp->tm_mday, tp->tm_mon + 1, tp->tm_year + 1900,
|
||||||
tp->tm_hour, tp->tm_min, tp->tm_sec);
|
tp->tm_hour, tp->tm_min, tp->tm_sec);
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ static void showfile(char *fname)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf(buf, "ERROR: file '%s' not found", fname);
|
snprintf(buf, sizeof(buf), "ERROR: file '%s' not found", fname);
|
||||||
errormsg(buf);
|
errormsg(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ int main(int argc, char **argv, char **envp)
|
|||||||
|
|
||||||
for (i = 0; ; i++)
|
for (i = 0; ; i++)
|
||||||
{
|
{
|
||||||
sprintf(outbuf, "Remote message %d", i);
|
snprintf(outbuf, sizeof(outbuf), "Remote message %d", i);
|
||||||
len = strlen(outbuf);
|
len = strlen(outbuf);
|
||||||
|
|
||||||
printf("client: Sending '%s' (%d bytes)\n", outbuf, len);
|
printf("client: Sending '%s' (%d bytes)\n", outbuf, len);
|
||||||
|
@ -163,7 +163,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
* from the poll.
|
* from the poll.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sprintf(buffer, "Message %d", count);
|
snprintf(buffer, sizeof(buffer), "Message %d", count);
|
||||||
nbytes = write(fd1, buffer, strlen(buffer));
|
nbytes = write(fd1, buffer, strlen(buffer));
|
||||||
if (nbytes < 0)
|
if (nbytes < 0)
|
||||||
{
|
{
|
||||||
|
@ -92,7 +92,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
sgreen = 1;
|
sgreen = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buffer, "#%02X%02X%02X", red, green, blue);
|
snprintf(buffer, sizeof(buffer), "#%02X%02X%02X", red, green, blue);
|
||||||
write(fd, buffer, 8);
|
write(fd, buffer, 8);
|
||||||
usleep(5000);
|
usleep(5000);
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,8 @@ static void readdirectories(const char *path, struct node_s *entry)
|
|||||||
|
|
||||||
/* Get the full path to the entry */
|
/* Get the full path to the entry */
|
||||||
|
|
||||||
sprintf(g_scratchbuffer, "%s/%s", path, direntry->d_name);
|
snprintf(g_scratchbuffer, sizeof(g_scratchbuffer),
|
||||||
|
"%s/%s", path, direntry->d_name);
|
||||||
fullpath = strdup(g_scratchbuffer);
|
fullpath = strdup(g_scratchbuffer);
|
||||||
|
|
||||||
if (DIRENT_ISDIRECTORY(direntry->d_type))
|
if (DIRENT_ISDIRECTORY(direntry->d_type))
|
||||||
|
@ -249,8 +249,9 @@ static void wgetjson_json_item_scan(cJSON *item, const char *prefix)
|
|||||||
while (item)
|
while (item)
|
||||||
{
|
{
|
||||||
const char *string = item->string ? item->string : "(null)";
|
const char *string = item->string ? item->string : "(null)";
|
||||||
newprefix = malloc(strlen(prefix) + strlen(string) + 2);
|
size_t len = strlen(prefix) + strlen(string) + 2;
|
||||||
sprintf(newprefix, "%s/%s", prefix, string);
|
newprefix = malloc(len);
|
||||||
|
snprintf(newprefix, len, "%s/%s", prefix, string);
|
||||||
|
|
||||||
dorecurse = wgetjson_json_item_callback(newprefix, item->type, item);
|
dorecurse = wgetjson_json_item_callback(newprefix, item->type, item);
|
||||||
if (item->child && dorecurse)
|
if (item->child && dorecurse)
|
||||||
|
@ -262,7 +262,8 @@ WINDOW *Xinitscr(int argc, char *argv[])
|
|||||||
|
|
||||||
def_shell_mode();
|
def_shell_mode();
|
||||||
|
|
||||||
sprintf(ttytype, "pdcurses|PDCurses for %s", PDC_sysname());
|
snprintf(ttytype, sizeof(ttytype),
|
||||||
|
"pdcurses|PDCurses for %s", PDC_sysname());
|
||||||
|
|
||||||
return stdscr;
|
return stdscr;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ static void dstack(char *fmt, int num, PANEL *pan)
|
|||||||
{
|
{
|
||||||
char s80[80];
|
char s80[80];
|
||||||
|
|
||||||
sprintf(s80, fmt, num, pan);
|
snprintf(s80, sizeof(s80), fmt, num, pan);
|
||||||
PDC_LOG(("%s b=%s t=%s", s80, _bottom_panel ? _bottom_panel->user : "--",
|
PDC_LOG(("%s b=%s t=%s", s80, _bottom_panel ? _bottom_panel->user : "--",
|
||||||
_top_panel ? _top_panel->user : "--"));
|
_top_panel ? _top_panel->user : "--"));
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ static void dtouchline(PANEL *pan, int start, int count)
|
|||||||
{
|
{
|
||||||
char s80[80];
|
char s80[80];
|
||||||
|
|
||||||
sprintf(s80, "dtouchline s=%d c=%d", start, count);
|
snprintf(s80, sizeof(s80), "dtouchline s=%d c=%d", start, count);
|
||||||
dpanel(s80, pan);
|
dpanel(s80, pan);
|
||||||
touchline(pan->win, start, count);
|
touchline(pan->win, start, count);
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ static struct Value *hex(struct Value *v, long int value, long int digits)
|
|||||||
{
|
{
|
||||||
char buf[sizeof(long int) * 2 + 1];
|
char buf[sizeof(long int) * 2 + 1];
|
||||||
|
|
||||||
sprintf(buf, "%0*lx", (int)digits, value);
|
snprintf(buf, sizeof(buf), "%0*lx", (int)digits, value);
|
||||||
Value_new_STRING(v);
|
Value_new_STRING(v);
|
||||||
String_appendChars(&v->u.string, buf);
|
String_appendChars(&v->u.string, buf);
|
||||||
return v;
|
return v;
|
||||||
@ -686,8 +686,9 @@ static struct Value *fn_date(struct Value *v, struct Auto *stack)
|
|||||||
String_size(&v->u.string, 10);
|
String_size(&v->u.string, 10);
|
||||||
time(&t);
|
time(&t);
|
||||||
now = localtime(&t);
|
now = localtime(&t);
|
||||||
sprintf(v->u.string.character, "%02d-%02d-%04d", now->tm_mon + 1,
|
snprintf(v->u.string.character, v->u.string.length + 1,
|
||||||
now->tm_mday, now->tm_year + 1900);
|
"%02d-%02d-%04d", now->tm_mon + 1,
|
||||||
|
now->tm_mday, now->tm_year + 1900);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -964,7 +965,7 @@ static struct Value *fn_hexi(struct Value *v, struct Auto *stack)
|
|||||||
{
|
{
|
||||||
char buf[sizeof(long int) * 2 + 1];
|
char buf[sizeof(long int) * 2 + 1];
|
||||||
|
|
||||||
sprintf(buf, "%lx", intValue(stack, 0));
|
snprintf(buf, sizeof(buf), "%lx", intValue(stack, 0));
|
||||||
Value_new_STRING(v);
|
Value_new_STRING(v);
|
||||||
String_appendChars(&v->u.string, buf);
|
String_appendChars(&v->u.string, buf);
|
||||||
return v;
|
return v;
|
||||||
@ -982,7 +983,7 @@ static struct Value *fn_hexd(struct Value *v, struct Auto *stack)
|
|||||||
return Value_new_ERROR(v, OUTOFRANGE, _("number"));
|
return Value_new_ERROR(v, OUTOFRANGE, _("number"));
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buf, "%lx", n);
|
snprintf(buf, sizeof(buf), "%lx", n);
|
||||||
Value_new_STRING(v);
|
Value_new_STRING(v);
|
||||||
String_appendChars(&v->u.string, buf);
|
String_appendChars(&v->u.string, buf);
|
||||||
return v;
|
return v;
|
||||||
@ -1639,7 +1640,7 @@ static struct Value *fn_oct(struct Value *v, struct Auto *stack)
|
|||||||
{
|
{
|
||||||
char buf[sizeof(long int) * 3 + 1];
|
char buf[sizeof(long int) * 3 + 1];
|
||||||
|
|
||||||
sprintf(buf, "%lo", intValue(stack, 0));
|
snprintf(buf, sizeof(buf), "%lo", intValue(stack, 0));
|
||||||
Value_new_STRING(v);
|
Value_new_STRING(v);
|
||||||
String_appendChars(&v->u.string, buf);
|
String_appendChars(&v->u.string, buf);
|
||||||
return v;
|
return v;
|
||||||
@ -1910,8 +1911,9 @@ static struct Value *fn_times(struct Value *v, struct Auto *stack)
|
|||||||
String_size(&v->u.string, 8);
|
String_size(&v->u.string, 8);
|
||||||
time(&t);
|
time(&t);
|
||||||
now = localtime(&t);
|
now = localtime(&t);
|
||||||
sprintf(v->u.string.character, "%02d:%02d:%02d", now->tm_hour, now->tm_min,
|
snprintf(v->u.string.character, v->u.string.length + 1,
|
||||||
now->tm_sec);
|
"%02d:%02d:%02d", now->tm_hour, now->tm_min,
|
||||||
|
now->tm_sec);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,8 @@ static void Xref_print(struct Xref *root,
|
|||||||
FS_putChars(chn, "\n ");
|
FS_putChars(chn, "\n ");
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buf, " %ld", Program_lineNumber(p, &cur->line));
|
snprintf(buf, sizeof(buf), " %ld",
|
||||||
|
Program_lineNumber(p, &cur->line));
|
||||||
FS_putChars(chn, buf);
|
FS_putChars(chn, buf);
|
||||||
}
|
}
|
||||||
while (cur != tail);
|
while (cur != tail);
|
||||||
@ -184,7 +185,8 @@ static void printLine(const void *k, struct Program *p, int chn)
|
|||||||
{
|
{
|
||||||
char buf[80];
|
char buf[80];
|
||||||
|
|
||||||
sprintf(buf, "%8ld", Program_lineNumber(p, (const struct Pc *)k));
|
snprintf(buf, sizeof(buf), "%8ld",
|
||||||
|
Program_lineNumber(p, (const struct Pc *)k));
|
||||||
FS_putChars(chn, buf);
|
FS_putChars(chn, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,7 +605,8 @@ void Program_trace(struct Program *this, struct Pc *pc, int dev, int tr)
|
|||||||
{
|
{
|
||||||
char buf[40];
|
char buf[40];
|
||||||
|
|
||||||
sprintf(buf, "<%ld>\n", this->code[pc->line]->u.integer);
|
snprintf(buf, sizeof(buf), "<%ld>\n",
|
||||||
|
this->code[pc->line]->u.integer);
|
||||||
FS_putChars(dev, buf);
|
FS_putChars(dev, buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2746,7 +2746,7 @@ static FAR char *strstring(void)
|
|||||||
x = expr();
|
x = expr();
|
||||||
match(CPAREN);
|
match(CPAREN);
|
||||||
|
|
||||||
sprintf(g_iobuffer, "%g", x);
|
snprintf(g_iobuffer, sizeof(g_iobuffer), "%g", x);
|
||||||
answer = mystrdup(g_iobuffer);
|
answer = mystrdup(g_iobuffer);
|
||||||
if (!answer)
|
if (!answer)
|
||||||
{
|
{
|
||||||
|
@ -332,7 +332,7 @@ static int chat_internalise(FAR struct chat *priv,
|
|||||||
|
|
||||||
if (rhs)
|
if (rhs)
|
||||||
{
|
{
|
||||||
len = strlen(tok->string);
|
len = strlen(tok->string) + 1;
|
||||||
if (!tok->no_termin)
|
if (!tok->no_termin)
|
||||||
{
|
{
|
||||||
/* Add space for the line terminator */
|
/* Add space for the line terminator */
|
||||||
@ -340,13 +340,13 @@ static int chat_internalise(FAR struct chat *priv,
|
|||||||
len += 2;
|
len += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
line->rhs = malloc(len + 1);
|
line->rhs = malloc(len);
|
||||||
if (line->rhs)
|
if (line->rhs)
|
||||||
{
|
{
|
||||||
/* Copy the token and add the line terminator as appropriate */
|
/* Copy the token and add the line terminator as appropriate */
|
||||||
|
|
||||||
sprintf(line->rhs, tok->no_termin ? "%s" : "%s\r\n",
|
snprintf(line->rhs, len,
|
||||||
tok->string);
|
tok->no_termin ? "%s" : "%s\r\n", tok->string);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -399,7 +399,7 @@ char *md5_hash(const uint8_t * addr, const size_t len)
|
|||||||
md5_sum(addr, len, digest);
|
md5_sum(addr, len, digest);
|
||||||
for (i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
sprintf(&hash[i * 2], "%02x", digest[i]);
|
snprintf(&hash[i * 2], 33 - i * 2, "%02x", digest[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
hash[32] = 0;
|
hash[32] = 0;
|
||||||
|
@ -1383,8 +1383,9 @@ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node,
|
|||||||
FAR struct ftpd_pathnode_s *node1;
|
FAR struct ftpd_pathnode_s *node1;
|
||||||
FAR struct ftpd_pathnode_s *node2;
|
FAR struct ftpd_pathnode_s *node2;
|
||||||
FAR char *path;
|
FAR char *path;
|
||||||
FAR size_t allocsize;
|
size_t allocsize;
|
||||||
FAR size_t namelen;
|
size_t namelen;
|
||||||
|
size_t next;
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
{
|
{
|
||||||
@ -1424,7 +1425,7 @@ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
allocsize += namelen +1;
|
allocsize += namelen + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1441,7 +1442,7 @@ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
allocsize = 0;
|
next = 0;
|
||||||
node1 = node;
|
node1 = node;
|
||||||
while (node1 != NULL)
|
while (node1 != NULL)
|
||||||
{
|
{
|
||||||
@ -1471,19 +1472,20 @@ static FAR char *ftpd_node2path(FAR struct ftpd_pathnode_s *node,
|
|||||||
{
|
{
|
||||||
if (namelen <= 0)
|
if (namelen <= 0)
|
||||||
{
|
{
|
||||||
allocsize += sprintf(&path[allocsize], "/");
|
snprintf(&path[next], allocsize - next, "/");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
allocsize += sprintf(&path[allocsize], "%s", node1->name);
|
snprintf(&path[next], allocsize - next, "%s", node1->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
allocsize += sprintf(&path[allocsize], "%s%s", node1->name, "/");
|
snprintf(&path[next], allocsize - next, "%s%s", node1->name, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
node1 = node1->flink;
|
node1 = node1->flink;
|
||||||
|
next += strlen(&path[next]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
@ -153,8 +153,8 @@ int tftpget_cb(FAR const char *remote, in_addr_t addr, bool binary,
|
|||||||
|
|
||||||
if (blockno == 1)
|
if (blockno == 1)
|
||||||
{
|
{
|
||||||
len = tftp_mkreqpacket(packet, TFTP_RRQ, remote,
|
len = tftp_mkreqpacket(packet, TFTP_IOBUFSIZE,
|
||||||
binary);
|
TFTP_RRQ, remote, binary);
|
||||||
server.sin_port = HTONS(CONFIG_NETUTILS_TFTP_PORT);
|
server.sin_port = HTONS(CONFIG_NETUTILS_TFTP_PORT);
|
||||||
ret = tftp_sendto(sd, packet, len, &server);
|
ret = tftp_sendto(sd, packet, len, &server);
|
||||||
if (ret != len)
|
if (ret != len)
|
||||||
|
@ -158,7 +158,7 @@
|
|||||||
/* Defined in tftp_packet.c *************************************************/
|
/* Defined in tftp_packet.c *************************************************/
|
||||||
|
|
||||||
extern int tftp_sockinit(struct sockaddr_in *server, in_addr_t addr);
|
extern int tftp_sockinit(struct sockaddr_in *server, in_addr_t addr);
|
||||||
extern int tftp_mkreqpacket(uint8_t *buffer, int opcode,
|
extern int tftp_mkreqpacket(uint8_t *buffer, size_t len, int opcode,
|
||||||
const char *path, bool binary);
|
const char *path, bool binary);
|
||||||
extern int tftp_mkackpacket(uint8_t *buffer, uint16_t blockno);
|
extern int tftp_mkackpacket(uint8_t *buffer, uint16_t blockno);
|
||||||
extern int tftp_mkerrpacket(uint8_t *buffer, uint16_t errorcode,
|
extern int tftp_mkerrpacket(uint8_t *buffer, uint16_t errorcode,
|
||||||
|
@ -122,13 +122,16 @@ int tftp_sockinit(struct sockaddr_in *server, in_addr_t addr)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int tftp_mkreqpacket(uint8_t *buffer, int opcode, const char *path,
|
int tftp_mkreqpacket(uint8_t *buffer, size_t len, int opcode,
|
||||||
bool binary)
|
const char *path, bool binary)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
buffer[0] = opcode >> 8;
|
buffer[0] = opcode >> 8;
|
||||||
buffer[1] = opcode & 0xff;
|
buffer[1] = opcode & 0xff;
|
||||||
return sprintf((char *)&buffer[2], "%s%c%s", path, 0,
|
ret = snprintf((char *)&buffer[2], len - 2, "%s%c%s", path, 0,
|
||||||
tftp_mode(binary)) + 3;
|
tftp_mode(binary)) + 3;
|
||||||
|
return ret < len ? ret : len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -302,7 +302,8 @@ int tftpput_cb(FAR const char *remote, in_addr_t addr, bool binary,
|
|||||||
retry = 0;
|
retry = 0;
|
||||||
for (; ; )
|
for (; ; )
|
||||||
{
|
{
|
||||||
packetlen = tftp_mkreqpacket(packet, TFTP_WRQ, remote, binary);
|
packetlen = tftp_mkreqpacket(packet, TFTP_IOBUFSIZE,
|
||||||
|
TFTP_WRQ, remote, binary);
|
||||||
ret = tftp_sendto(sd, packet, packetlen, &server);
|
ret = tftp_sendto(sd, packet, packetlen, &server);
|
||||||
if (ret != packetlen)
|
if (ret != packetlen)
|
||||||
{
|
{
|
||||||
|
@ -179,14 +179,15 @@ int main(int argc, char *argv[])
|
|||||||
path_info = getenv("PATH_INFO");
|
path_info = getenv("PATH_INFO");
|
||||||
if (path_info)
|
if (path_info)
|
||||||
{
|
{
|
||||||
cp = (char *)malloc(strlen(script_name) + strlen(path_info) + 1);
|
size_t len = strlen(script_name) + strlen(path_info) + 1;
|
||||||
|
cp = (char *)malloc(len);
|
||||||
if (!cp)
|
if (!cp)
|
||||||
{
|
{
|
||||||
internal_error("Out of memory.");
|
internal_error("Out of memory.");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(cp, "%s%s", script_name, path_info);
|
snprintf(cp, len, "%s%s", script_name, path_info);
|
||||||
script_name = cp;
|
script_name = cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,8 @@ static int check_filename(char *filename)
|
|||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
authname = malloc(strlen(dirname) + 1 + sizeof(CONFIG_AUTH_FILE));
|
fnl = strlen(dirname) + 1 + sizeof(CONFIG_AUTH_FILE);
|
||||||
|
authname = malloc(fnl);
|
||||||
if (!authname)
|
if (!authname)
|
||||||
{
|
{
|
||||||
/* out of memory */
|
/* out of memory */
|
||||||
@ -333,7 +334,7 @@ static int check_filename(char *filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(authname, "%s/%s", dirname, CONFIG_AUTH_FILE);
|
snprintf(authname, fnl, "%s/%s", dirname, CONFIG_AUTH_FILE);
|
||||||
r = stat(authname, &sb);
|
r = stat(authname, &sb);
|
||||||
|
|
||||||
free(dirname);
|
free(dirname);
|
||||||
@ -907,6 +908,7 @@ int main(int argc, char *argv[])
|
|||||||
char *script_name;
|
char *script_name;
|
||||||
char *path_info;
|
char *path_info;
|
||||||
char *path_translated;
|
char *path_translated;
|
||||||
|
size_t len;
|
||||||
int errcode = 0;
|
int errcode = 0;
|
||||||
|
|
||||||
/* Default formats. */
|
/* Default formats. */
|
||||||
@ -935,14 +937,15 @@ int main(int argc, char *argv[])
|
|||||||
path_info = "";
|
path_info = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
g_url = (char *)malloc(strlen(script_name) + strlen(path_info) + 1);
|
len = strlen(script_name) + strlen(path_info) + 1;
|
||||||
|
g_url = (char *)malloc(len);
|
||||||
if (!g_url)
|
if (!g_url)
|
||||||
{
|
{
|
||||||
internal_error("Out of memory.");
|
internal_error("Out of memory.");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(g_url, "%s%s", script_name, path_info);
|
snprintf(g_url, len, "%s%s", script_name, path_info);
|
||||||
|
|
||||||
/* Get the name of the file to parse. */
|
/* Get the name of the file to parse. */
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ void httpd_strencode(char *to, int tosize, char *from)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf(to, "%%%02x", (int)*from & 0xff);
|
snprintf(to, tosize - tolen, "%%%02x", (int)*from & 0xff);
|
||||||
to += 3;
|
to += 3;
|
||||||
tolen += 3;
|
tolen += 3;
|
||||||
}
|
}
|
||||||
|
@ -1770,7 +1770,7 @@ int webclient_perform(FAR struct webclient_context *ctx)
|
|||||||
char post_size[sizeof("18446744073709551615")];
|
char post_size[sizeof("18446744073709551615")];
|
||||||
|
|
||||||
dest = append(dest, ep, g_httpcontsize);
|
dest = append(dest, ep, g_httpcontsize);
|
||||||
sprintf(post_size, "%zu", ctx->bodylen);
|
snprintf(post_size, sizeof(post_size), "%zu", ctx->bodylen);
|
||||||
dest = append(dest, ep, post_size);
|
dest = append(dest, ep, post_size);
|
||||||
dest = append(dest, ep, g_httpcrnl);
|
dest = append(dest, ep, g_httpcrnl);
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,7 @@ int xmlrpc_getstring(struct xmlrpc_s *xmlcall, char *arg)
|
|||||||
int xmlrpc_buildresponse(struct xmlrpc_s *xmlcall, char *args, ...)
|
int xmlrpc_buildresponse(struct xmlrpc_s *xmlcall, char *args, ...)
|
||||||
{
|
{
|
||||||
va_list argp;
|
va_list argp;
|
||||||
|
int next = 0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int close = 0;
|
int close = 0;
|
||||||
int isstruct = 0;
|
int isstruct = 0;
|
||||||
@ -195,6 +196,7 @@ int xmlrpc_buildresponse(struct xmlrpc_s *xmlcall, char *args, ...)
|
|||||||
sizeof(xmlcall->response));
|
sizeof(xmlcall->response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
next = strlen(xmlcall->response);
|
||||||
va_start(argp, args);
|
va_start(argp, args);
|
||||||
|
|
||||||
while (args[index])
|
while (args[index])
|
||||||
@ -203,10 +205,15 @@ int xmlrpc_buildresponse(struct xmlrpc_s *xmlcall, char *args, ...)
|
|||||||
{
|
{
|
||||||
if ((args[index] != '{') && (args[index] != '}'))
|
if ((args[index] != '{') && (args[index] != '}'))
|
||||||
{
|
{
|
||||||
sprintf(&xmlcall->response[strlen(xmlcall->response)],
|
snprintf(&xmlcall->response[next],
|
||||||
" <member>\n");
|
sizeof(xmlcall->response) - next,
|
||||||
sprintf(&xmlcall->response[strlen(xmlcall->response)],
|
" <member>\n");
|
||||||
" <name>%s</name>\n", va_arg(argp, char *));
|
next += strlen(&xmlcall->response[next]);
|
||||||
|
snprintf(&xmlcall->response[next],
|
||||||
|
sizeof(xmlcall->response) - next,
|
||||||
|
" <name>%s</name>\n",
|
||||||
|
va_arg(argp, char *));
|
||||||
|
next += strlen(&xmlcall->response[next]);
|
||||||
close = 1;
|
close = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,39 +221,45 @@ int xmlrpc_buildresponse(struct xmlrpc_s *xmlcall, char *args, ...)
|
|||||||
switch (args[index])
|
switch (args[index])
|
||||||
{
|
{
|
||||||
case '{':
|
case '{':
|
||||||
sprintf(&xmlcall->response[strlen(xmlcall->response)],
|
snprintf(&xmlcall->response[next],
|
||||||
" <value><struct>\n");
|
sizeof(xmlcall->response) - next,
|
||||||
|
" <value><struct>\n");
|
||||||
isstruct = 1;
|
isstruct = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '}':
|
case '}':
|
||||||
sprintf(&xmlcall->response[strlen(xmlcall->response)],
|
snprintf(&xmlcall->response[next],
|
||||||
" </struct></value>\n");
|
sizeof(xmlcall->response) - next,
|
||||||
|
" </struct></value>\n");
|
||||||
isstruct = 0;
|
isstruct = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
i = va_arg(argp, int);
|
i = va_arg(argp, int);
|
||||||
sprintf(&xmlcall->response[strlen(xmlcall->response)],
|
snprintf(&xmlcall->response[next],
|
||||||
" <value><int>%d</int></value>\r\n", i);
|
sizeof(xmlcall->response) - next,
|
||||||
|
" <value><int>%d</int></value>\r\n", i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b':
|
case 'b':
|
||||||
i = va_arg(argp, int);
|
i = va_arg(argp, int);
|
||||||
sprintf(&xmlcall->response[strlen(xmlcall->response)],
|
snprintf(&xmlcall->response[next],
|
||||||
|
sizeof(xmlcall->response) - next,
|
||||||
" <value><boolean>%d</boolean></value>\r\n", i);
|
" <value><boolean>%d</boolean></value>\r\n", i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
d = va_arg(argp, double);
|
d = va_arg(argp, double);
|
||||||
sprintf(&xmlcall->response[strlen(xmlcall->response)],
|
snprintf(&xmlcall->response[next],
|
||||||
" <value><double>%f</double></value>\r\n", d);
|
sizeof(xmlcall->response) - next,
|
||||||
|
" <value><double>%f</double></value>\r\n", d);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
s = va_arg(argp, char *);
|
s = va_arg(argp, char *);
|
||||||
sprintf(&xmlcall->response[strlen(xmlcall->response)],
|
snprintf(&xmlcall->response[next],
|
||||||
" <value><string>%s</string></value>\r\n", s);
|
sizeof(xmlcall->response) - next,
|
||||||
|
" <value><string>%s</string></value>\r\n", s);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -254,10 +267,13 @@ int xmlrpc_buildresponse(struct xmlrpc_s *xmlcall, char *args, ...)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
next += strlen(&xmlcall->response[next]);
|
||||||
if (close)
|
if (close)
|
||||||
{
|
{
|
||||||
sprintf(&xmlcall->response[strlen(xmlcall->response)],
|
snprintf(&xmlcall->response[next],
|
||||||
" </member>\n");
|
sizeof(xmlcall->response) - next,
|
||||||
|
" </member>\n");
|
||||||
|
next += strlen(&xmlcall->response[next]);
|
||||||
close = 0;
|
close = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,19 +297,22 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, FAR const char *msg,
|
|||||||
nsh_output(vtbl, "%s:\n", msg);
|
nsh_output(vtbl, "%s:\n", msg);
|
||||||
for (i = 0; i < nbytes; i += 16)
|
for (i = 0; i < nbytes; i += 16)
|
||||||
{
|
{
|
||||||
sprintf(line, "%04x: ", i);
|
snprintf(line, sizeof(line), "%04x: ", i);
|
||||||
|
size = strlen(line);
|
||||||
|
|
||||||
for (j = 0; j < 16; j++)
|
for (j = 0; j < 16; j++)
|
||||||
{
|
{
|
||||||
size = strlen(line);
|
|
||||||
if (i + j < nbytes)
|
if (i + j < nbytes)
|
||||||
{
|
{
|
||||||
sprintf(&line[size], "%02x ", buffer[i + j]);
|
snprintf(&line[size], sizeof(line) - size,
|
||||||
|
"%02x ", buffer[i + j]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strlcpy(&line[size], " ", sizeof(line) - size);
|
strlcpy(&line[size], " ", sizeof(line) - size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size += strlen(&line[size]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < 16; j++)
|
for (j = 0; j < 16; j++)
|
||||||
@ -317,8 +320,9 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, FAR const char *msg,
|
|||||||
if (i + j < nbytes)
|
if (i + j < nbytes)
|
||||||
{
|
{
|
||||||
ch = buffer[i + j];
|
ch = buffer[i + j];
|
||||||
sprintf(&line[strlen(line)], "%c",
|
snprintf(&line[size], sizeof(line) - size,
|
||||||
ch >= 0x20 && ch <= 0x7e ? ch : '.');
|
"%c", ch >= 0x20 && ch <= 0x7e ? ch : '.');
|
||||||
|
size += strlen(&line[size]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ int nsh_setvar(FAR struct nsh_vtbl_s *vtbl, FAR const char *name,
|
|||||||
|
|
||||||
/* Now, put the new name=value string into the NSH variable buffer */
|
/* Now, put the new name=value string into the NSH variable buffer */
|
||||||
|
|
||||||
sprintf(pair, "%s=%s", name, value);
|
snprintf(pair, varlen, "%s=%s", name, value);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -562,9 +562,11 @@ static void cfgdatacmd_show_all_config_items(void)
|
|||||||
/* Print header */
|
/* Print header */
|
||||||
|
|
||||||
#ifdef CONFIG_MTD_CONFIG_NAMED
|
#ifdef CONFIG_MTD_CONFIG_NAMED
|
||||||
sprintf(fmtstr, "%%-%ds%%-6sData\n", CONFIG_MTD_CONFIG_NAME_LEN);
|
snprintf(fmtstr, sizeof(fmtstr),
|
||||||
|
"%%-%ds%%-6sData\n", CONFIG_MTD_CONFIG_NAME_LEN);
|
||||||
printf(fmtstr, "Name", "Len");
|
printf(fmtstr, "Name", "Len");
|
||||||
sprintf(fmtstr, "%%-%ds%%-6d", CONFIG_MTD_CONFIG_NAME_LEN);
|
snprintf(fmtstr, sizeof(fmtstr),
|
||||||
|
"%%-%ds%%-6d", CONFIG_MTD_CONFIG_NAME_LEN);
|
||||||
#else
|
#else
|
||||||
strlcpy(fmtstr, "%-6s%-6s%-6sData\n", sizeof(fmtstr));
|
strlcpy(fmtstr, "%-6s%-6s%-6sData\n", sizeof(fmtstr));
|
||||||
printf(fmtstr, "ID", "Inst", "Len");
|
printf(fmtstr, "ID", "Inst", "Len");
|
||||||
@ -618,7 +620,8 @@ static void cfgdatacmd_show_all_config_items(void)
|
|||||||
char fmtstr2[10];
|
char fmtstr2[10];
|
||||||
|
|
||||||
#ifdef CONFIG_MTD_CONFIG_NAMED
|
#ifdef CONFIG_MTD_CONFIG_NAMED
|
||||||
sprintf(fmtstr2, "\n%ds", CONFIG_MTD_CONFIG_NAME_LEN + 6);
|
snprintf(fmtstr2, sizeof(fmtstr2),
|
||||||
|
"\n%ds", CONFIG_MTD_CONFIG_NAME_LEN + 6);
|
||||||
#else
|
#else
|
||||||
strlcpy(fmtstr2, "\n%18s", sizeof(fmtstr2));
|
strlcpy(fmtstr2, "\n%18s", sizeof(fmtstr2));
|
||||||
#endif
|
#endif
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
#define NTP_TIME_STR_MAX_LEN (1 + 21 + 1 + 9 + 1)
|
#define NTP_TIME_STR_MAX_LEN (1 + 21 + 1 + 9 + 1)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
format_ntptimestamp(int64_t ts, FAR char *buf)
|
format_ntptimestamp(int64_t ts, FAR char *buf, size_t len)
|
||||||
{
|
{
|
||||||
FAR const char *sign;
|
FAR const char *sign;
|
||||||
uint64_t absts;
|
uint64_t absts;
|
||||||
@ -61,9 +61,9 @@ format_ntptimestamp(int64_t ts, FAR char *buf)
|
|||||||
absts = ts;
|
absts = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buf, "%s%" PRIu64 ".%09" PRIu64,
|
snprintf(buf, len, "%s%" PRIu64 ".%09" PRIu64,
|
||||||
sign, absts >> 32,
|
sign, absts >> 32,
|
||||||
((absts & 0xffffffff) * NSEC_PER_SEC) >> 32);
|
((absts & 0xffffffff) * NSEC_PER_SEC) >> 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -115,8 +115,10 @@ int main(int argc, FAR char *argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
format_ntptimestamp(status.samples[i].offset, offset_buf);
|
format_ntptimestamp(status.samples[i].offset,
|
||||||
format_ntptimestamp(status.samples[i].delay, delay_buf);
|
offset_buf, sizeof(offset_buf));
|
||||||
|
format_ntptimestamp(status.samples[i].delay,
|
||||||
|
delay_buf, sizeof(delay_buf));
|
||||||
printf("[%u] srv %s offset %s delay %s\n",
|
printf("[%u] srv %s offset %s delay %s\n",
|
||||||
i, name, offset_buf, delay_buf);
|
i, name, offset_buf, delay_buf);
|
||||||
}
|
}
|
||||||
|
@ -729,7 +729,9 @@ static void dump_notes(size_t nread)
|
|||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
ret += sprintf(&out[ret], " 0x%x", note_binary->nbi_data[i]);
|
snprintf(&out[ret], sizeof(out) - ret,
|
||||||
|
" 0x%x", note_binary->nbi_data[i]);
|
||||||
|
ret += strlen(&out[ret]);
|
||||||
}
|
}
|
||||||
|
|
||||||
trace_dump_unflatten(&ip, note_binary->nbi_ip,
|
trace_dump_unflatten(&ip, note_binary->nbi_ip,
|
||||||
|
@ -917,9 +917,9 @@ static int tcurses_vt100_setcolors(FAR struct termcurses_s *dev,
|
|||||||
|
|
||||||
if ((colors->color_mask & TCURS_COLOR_FG) != 0)
|
if ((colors->color_mask & TCURS_COLOR_FG) != 0)
|
||||||
{
|
{
|
||||||
sprintf(str, g_setfgcolor,
|
snprintf(str, sizeof(str), g_setfgcolor,
|
||||||
tcurses_vt100_getcolorindex(colors->fg_red, colors->fg_green,
|
tcurses_vt100_getcolorindex(colors->fg_red, colors->fg_green,
|
||||||
colors->fg_blue));
|
colors->fg_blue));
|
||||||
ret = write(fd, str, strlen(str));
|
ret = write(fd, str, strlen(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -932,9 +932,9 @@ static int tcurses_vt100_setcolors(FAR struct termcurses_s *dev,
|
|||||||
colors->bg_red = 0;
|
colors->bg_red = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(str, g_setbgcolor,
|
snprintf(str, sizeof(str), g_setbgcolor,
|
||||||
tcurses_vt100_getcolorindex(colors->bg_red, colors->bg_green,
|
tcurses_vt100_getcolorindex(colors->bg_red, colors->bg_green,
|
||||||
colors->bg_blue));
|
colors->bg_blue));
|
||||||
ret = write(fd, str, strlen(str));
|
ret = write(fd, str, strlen(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,6 +228,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
uint8_t uniqueid[CONFIG_BOARDCTL_UNIQUEID_SIZE];
|
uint8_t uniqueid[CONFIG_BOARDCTL_UNIQUEID_SIZE];
|
||||||
FAR char *formatter;
|
FAR char *formatter;
|
||||||
|
size_t len;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
struct cfg_s cfg =
|
struct cfg_s cfg =
|
||||||
@ -258,8 +259,9 @@ int main(int argc, FAR char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
formatter = malloc(strlen(cfg.format) + 2);
|
len = strlen(cfg.format) + 2;
|
||||||
sprintf(formatter, "%%%s", cfg.format);
|
formatter = malloc(len);
|
||||||
|
snprintf(formatter, len, "%%%s", cfg.format);
|
||||||
|
|
||||||
if (cfg.prefix != NULL)
|
if (cfg.prefix != NULL)
|
||||||
{
|
{
|
||||||
|
@ -128,8 +128,8 @@ static int pubsubtest_thread_entry(int argc, FAR char *argv[])
|
|||||||
char fname[32];
|
char fname[32];
|
||||||
FAR FILE *f;
|
FAR FILE *f;
|
||||||
|
|
||||||
sprintf(fname, CONFIG_UORB_SRORAGE_DIR"/uorb_timings%u.txt",
|
snprintf(fname, sizeof(fname),
|
||||||
timingsgroup);
|
CONFIG_UORB_SRORAGE_DIR"/uorb_timings%u.txt", timingsgroup);
|
||||||
|
|
||||||
f = fopen(fname, "w");
|
f = fopen(fname, "w");
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -758,7 +759,7 @@ static void vi_setcursor(FAR struct vi_s *vi, uint16_t row, uint16_t column)
|
|||||||
|
|
||||||
/* Send the VT100 CURSORPOS command */
|
/* Send the VT100 CURSORPOS command */
|
||||||
|
|
||||||
vi_write(vi, buffer, len);
|
vi_write(vi, buffer, MIN(len, sizeof(buffer)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -858,10 +859,13 @@ static void vi_printf(FAR struct vi_s *vi, FAR const char *prefix,
|
|||||||
|
|
||||||
/* Expand the prefix message in the scratch buffer */
|
/* Expand the prefix message in the scratch buffer */
|
||||||
|
|
||||||
len = prefix ? snprintf(vi->scratch, SCRATCH_BUFSIZE, "%s", prefix) : 0;
|
len = prefix ? snprintf(vi->scratch,
|
||||||
|
sizeof(vi->scratch), "%s", prefix) : 0;
|
||||||
|
len = MIN(len, sizeof(vi->scratch));
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
len += vsnprintf(vi->scratch + len, SCRATCH_BUFSIZE - len, fmt, ap);
|
len += vsnprintf(vi->scratch + len, sizeof(vi->scratch) - len, fmt, ap);
|
||||||
|
len = MIN(len, sizeof(vi->scratch));
|
||||||
vvidbg(fmt, ap);
|
vvidbg(fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
@ -1299,8 +1303,8 @@ static bool vi_savetext(FAR struct vi_s *vi, FAR const char *filename,
|
|||||||
|
|
||||||
fclose(stream);
|
fclose(stream);
|
||||||
|
|
||||||
len = sprintf(vi->scratch, "%dC written", nwritten);
|
len = snprintf(vi->scratch, sizeof(vi->scratch), "%dC written", nwritten);
|
||||||
vi_write(vi, vi->scratch, len);
|
vi_write(vi, vi->scratch, MIN(len, sizeof(vi->scratch)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1955,10 +1959,10 @@ static void vi_showlinecol(FAR struct vi_s *vi)
|
|||||||
vi_cursoroff(vi);
|
vi_cursoroff(vi);
|
||||||
vi_setcursor(vi, vi->display.row - 1, vi->display.column - 15);
|
vi_setcursor(vi, vi->display.row - 1, vi->display.column - 15);
|
||||||
|
|
||||||
len = snprintf(vi->scratch, SCRATCH_BUFSIZE, "%jd,%d",
|
len = snprintf(vi->scratch, sizeof(vi->scratch), "%jd,%d",
|
||||||
(uintmax_t)(vi->cursor.row + vi->vscroll + 1),
|
(uintmax_t)(vi->cursor.row + vi->vscroll + 1),
|
||||||
vi->cursor.column + vi->hscroll + 1);
|
vi->cursor.column + vi->hscroll + 1);
|
||||||
vi_write(vi, vi->scratch, len);
|
vi_write(vi, vi->scratch, MIN(len, sizeof(vi->scratch)));
|
||||||
|
|
||||||
vi_clrtoeol(vi);
|
vi_clrtoeol(vi);
|
||||||
vi_cursoron(vi);
|
vi_cursoron(vi);
|
||||||
|
@ -705,7 +705,7 @@ static int zms_sendzsinit(FAR struct zm_state_s *pzm)
|
|||||||
static int zms_sendfilename(FAR struct zm_state_s *pzm)
|
static int zms_sendfilename(FAR struct zm_state_s *pzm)
|
||||||
{
|
{
|
||||||
FAR struct zms_state_s *pzms = (FAR struct zms_state_s *)pzm;
|
FAR struct zms_state_s *pzms = (FAR struct zms_state_s *)pzm;
|
||||||
FAR uint8_t *ptr = pzm->scratch;
|
FAR char *ptr = (FAR char *)pzm->scratch;
|
||||||
int len;
|
int len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -768,19 +768,19 @@ static int zms_sendfilename(FAR struct zm_state_s *pzm)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_SYSTEM_ZMODEM_TIMESTAMPS
|
#ifdef CONFIG_SYSTEM_ZMODEM_TIMESTAMPS
|
||||||
sprintf((FAR char *)ptr, "%ld %lo 0 %d 1 %ld 0",
|
snprintf(ptr, sizeof(pzm->scratch), "%ld %lo 0 %d 1 %ld 0",
|
||||||
(unsigned long)pzms->filesize, (unsigned long)pzms->timestamp,
|
(unsigned long)pzms->filesize, (unsigned long)pzms->timestamp,
|
||||||
CONFIG_SYSTEM_ZMODEM_SERIALNO, (unsigned long)pzms->filesize);
|
CONFIG_SYSTEM_ZMODEM_SERIALNO, (unsigned long)pzms->filesize);
|
||||||
#else
|
#else
|
||||||
sprintf((FAR char *)ptr, "%ld 0 0 %d 1 %ld 0",
|
snprintf(ptr, sizeof(pzm->scratch), "%ld 0 0 %d 1 %ld 0",
|
||||||
(unsigned long)pzms->filesize, CONFIG_SYSTEM_ZMODEM_SERIALNO,
|
(unsigned long)pzms->filesize, CONFIG_SYSTEM_ZMODEM_SERIALNO,
|
||||||
(unsigned long)pzms->filesize);
|
(unsigned long)pzms->filesize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ptr += strlen((FAR char *)ptr);
|
ptr += strlen(ptr);
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
|
|
||||||
len = ptr - pzm->scratch;
|
len = ptr - (FAR char *)pzm->scratch;
|
||||||
DEBUGASSERT(len < CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE);
|
DEBUGASSERT(len < CONFIG_SYSTEM_ZMODEM_SNDBUFSIZE);
|
||||||
return zm_senddata(pzm, pzm->scratch, len);
|
return zm_senddata(pzm, pzm->scratch, len);
|
||||||
}
|
}
|
||||||
|
@ -859,7 +859,7 @@ static void test_nvs_gc(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
/* 4 byte key */
|
/* 4 byte key */
|
||||||
|
|
||||||
sprintf(data.name, "k%02d", id);
|
snprintf(data.name, sizeof(data.name), "k%02d", id);
|
||||||
data.configdata = buf;
|
data.configdata = buf;
|
||||||
data.len = sizeof(buf);
|
data.len = sizeof(buf);
|
||||||
|
|
||||||
@ -876,7 +876,7 @@ static void test_nvs_gc(struct mtdnvs_ctx_s *ctx)
|
|||||||
{
|
{
|
||||||
/* 4 byte key */
|
/* 4 byte key */
|
||||||
|
|
||||||
sprintf(data.name, "k%02d", id);
|
snprintf(data.name, sizeof(data.name), "k%02d", id);
|
||||||
data.configdata = rd_buf;
|
data.configdata = rd_buf;
|
||||||
data.len = sizeof(rd_buf);
|
data.len = sizeof(rd_buf);
|
||||||
|
|
||||||
@ -929,7 +929,7 @@ static void test_nvs_gc(struct mtdnvs_ctx_s *ctx)
|
|||||||
{
|
{
|
||||||
/* 4 byte key */
|
/* 4 byte key */
|
||||||
|
|
||||||
sprintf(data.name, "k%02d", id);
|
snprintf(data.name, sizeof(data.name), "k%02d", id);
|
||||||
data.configdata = rd_buf;
|
data.configdata = rd_buf;
|
||||||
data.len = sizeof(rd_buf);
|
data.len = sizeof(rd_buf);
|
||||||
|
|
||||||
@ -1006,7 +1006,7 @@ static int write_content(uint16_t max_id, uint16_t begin, uint16_t end)
|
|||||||
|
|
||||||
/* 4 byte key */
|
/* 4 byte key */
|
||||||
|
|
||||||
sprintf(data.name, "k%02d", id);
|
snprintf(data.name, sizeof(data.name), "k%02d", id);
|
||||||
data.configdata = buf;
|
data.configdata = buf;
|
||||||
data.len = sizeof(buf);
|
data.len = sizeof(buf);
|
||||||
|
|
||||||
@ -1054,7 +1054,7 @@ static int check_content(uint16_t max_id)
|
|||||||
{
|
{
|
||||||
/* 4 byte key */
|
/* 4 byte key */
|
||||||
|
|
||||||
sprintf(data.name, "k%02d", id);
|
snprintf(data.name, sizeof(data.name), "k%02d", id);
|
||||||
data.configdata = rd_buf;
|
data.configdata = rd_buf;
|
||||||
data.len = sizeof(rd_buf);
|
data.len = sizeof(rd_buf);
|
||||||
|
|
||||||
@ -1512,7 +1512,7 @@ static void test_nvs_full_sector(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
sprintf(data.name, "k%04x", filling_id);
|
snprintf(data.name, sizeof(data.name), "k%04x", filling_id);
|
||||||
data.configdata = (FAR uint8_t *)&filling_id;
|
data.configdata = (FAR uint8_t *)&filling_id;
|
||||||
data.len = sizeof(filling_id);
|
data.len = sizeof(filling_id);
|
||||||
|
|
||||||
@ -1533,7 +1533,7 @@ static void test_nvs_full_sector(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
/* check whether can delete whatever from full storage */
|
/* check whether can delete whatever from full storage */
|
||||||
|
|
||||||
sprintf(data.name, "k%04x", 1);
|
snprintf(data.name, sizeof(data.name), "k%04x", 1);
|
||||||
data.configdata = NULL;
|
data.configdata = NULL;
|
||||||
data.len = 0;
|
data.len = 0;
|
||||||
|
|
||||||
@ -1565,7 +1565,7 @@ static void test_nvs_full_sector(struct mtdnvs_ctx_s *ctx)
|
|||||||
goto test_fail;
|
goto test_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(data.name, "k%04x", filling_id);
|
snprintf(data.name, sizeof(data.name), "k%04x", filling_id);
|
||||||
data.configdata = (FAR uint8_t *)&filling_id;
|
data.configdata = (FAR uint8_t *)&filling_id;
|
||||||
data.len = sizeof(filling_id);
|
data.len = sizeof(filling_id);
|
||||||
|
|
||||||
@ -1581,7 +1581,7 @@ static void test_nvs_full_sector(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
for (i = 0; i <= filling_id; i++)
|
for (i = 0; i <= filling_id; i++)
|
||||||
{
|
{
|
||||||
sprintf(data.name, "k%04x", i);
|
snprintf(data.name, sizeof(data.name), "k%04x", i);
|
||||||
data.configdata = (FAR uint8_t *)&data_read;
|
data.configdata = (FAR uint8_t *)&data_read;
|
||||||
data.len = sizeof(data_read);
|
data.len = sizeof(data_read);
|
||||||
|
|
||||||
@ -1997,7 +1997,7 @@ static void test_nvs_gc_touched_deleted_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
sprintf(data.name, "k%04x", filling_id);
|
snprintf(data.name, sizeof(data.name), "k%04x", filling_id);
|
||||||
data.configdata = (FAR uint8_t *)&filling_id;
|
data.configdata = (FAR uint8_t *)&filling_id;
|
||||||
data.len = sizeof(filling_id);
|
data.len = sizeof(filling_id);
|
||||||
|
|
||||||
@ -2032,7 +2032,7 @@ static void test_nvs_gc_touched_deleted_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
* B(deleted) A gc
|
* B(deleted) A gc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sprintf(data.name, "k%04x", filling_id - 1);
|
snprintf(data.name, sizeof(data.name), "k%04x", filling_id - 1);
|
||||||
data.configdata = NULL;
|
data.configdata = NULL;
|
||||||
data.len = 0;
|
data.len = 0;
|
||||||
ret = ioctl(fd, CFGDIOC_DELCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_DELCONFIG, &data);
|
||||||
@ -2049,7 +2049,7 @@ static void test_nvs_gc_touched_deleted_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
filling_id -= 1;
|
filling_id -= 1;
|
||||||
sprintf(data.name, "k%04x", filling_id);
|
snprintf(data.name, sizeof(data.name), "k%04x", filling_id);
|
||||||
data.configdata = (FAR uint8_t *)&filling_id;
|
data.configdata = (FAR uint8_t *)&filling_id;
|
||||||
data.len = sizeof(filling_id);
|
data.len = sizeof(filling_id);
|
||||||
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
||||||
@ -2064,7 +2064,7 @@ static void test_nvs_gc_touched_deleted_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
for (i = 0; i <= filling_id; i++)
|
for (i = 0; i <= filling_id; i++)
|
||||||
{
|
{
|
||||||
sprintf(data.name, "k%04x", i);
|
snprintf(data.name, sizeof(data.name), "k%04x", i);
|
||||||
data.configdata = (FAR uint8_t *)&data_read;
|
data.configdata = (FAR uint8_t *)&data_read;
|
||||||
data.len = sizeof(data_read);
|
data.len = sizeof(data_read);
|
||||||
|
|
||||||
@ -2146,7 +2146,7 @@ static void test_nvs_gc_touched_expired_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
sprintf(data.name, "k%04x", filling_id);
|
snprintf(data.name, sizeof(data.name), "k%04x", filling_id);
|
||||||
data.configdata = (FAR uint8_t *)&filling_id;
|
data.configdata = (FAR uint8_t *)&filling_id;
|
||||||
data.len = sizeof(filling_id);
|
data.len = sizeof(filling_id);
|
||||||
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
||||||
@ -2170,7 +2170,7 @@ static void test_nvs_gc_touched_expired_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
* B A(deleted) gc
|
* B A(deleted) gc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sprintf(data.name, "k%04x", 1);
|
snprintf(data.name, sizeof(data.name), "k%04x", 1);
|
||||||
data.configdata = NULL;
|
data.configdata = NULL;
|
||||||
data.len = 0;
|
data.len = 0;
|
||||||
ret = ioctl(fd, CFGDIOC_DELCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_DELCONFIG, &data);
|
||||||
@ -2207,7 +2207,7 @@ static void test_nvs_gc_touched_expired_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
update_id = 3;
|
update_id = 3;
|
||||||
sprintf(data.name, "k%04x", 2);
|
snprintf(data.name, sizeof(data.name), "k%04x", 2);
|
||||||
data.configdata = (FAR uint8_t *)&update_id;
|
data.configdata = (FAR uint8_t *)&update_id;
|
||||||
data.len = sizeof(update_id);
|
data.len = sizeof(update_id);
|
||||||
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
||||||
@ -2222,7 +2222,7 @@ static void test_nvs_gc_touched_expired_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
for (i = 0; i <= filling_id - 1; i++)
|
for (i = 0; i <= filling_id - 1; i++)
|
||||||
{
|
{
|
||||||
sprintf(data.name, "k%04x", i);
|
snprintf(data.name, sizeof(data.name), "k%04x", i);
|
||||||
data.configdata = (FAR uint8_t *)&data_read;
|
data.configdata = (FAR uint8_t *)&data_read;
|
||||||
data.len = sizeof(data_read);
|
data.len = sizeof(data_read);
|
||||||
ret = ioctl(fd, CFGDIOC_GETCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_GETCONFIG, &data);
|
||||||
@ -2323,7 +2323,7 @@ static void test_nvs_gc_not_touched_expired_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
sprintf(data.name, "k%04x", filling_id);
|
snprintf(data.name, sizeof(data.name), "k%04x", filling_id);
|
||||||
data.configdata = (FAR uint8_t *)&filling_id;
|
data.configdata = (FAR uint8_t *)&filling_id;
|
||||||
data.len = sizeof(filling_id);
|
data.len = sizeof(filling_id);
|
||||||
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
||||||
@ -2347,7 +2347,7 @@ static void test_nvs_gc_not_touched_expired_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
* B(deleted) A gc
|
* B(deleted) A gc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sprintf(data.name, "k%04x", filling_id - 1);
|
snprintf(data.name, sizeof(data.name), "k%04x", filling_id - 1);
|
||||||
data.configdata = NULL;
|
data.configdata = NULL;
|
||||||
data.len = 0;
|
data.len = 0;
|
||||||
ret = ioctl(fd, CFGDIOC_DELCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_DELCONFIG, &data);
|
||||||
@ -2364,7 +2364,7 @@ static void test_nvs_gc_not_touched_expired_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
update_id = 3;
|
update_id = 3;
|
||||||
sprintf(data.name, "k%04x", 2);
|
snprintf(data.name, sizeof(data.name), "k%04x", 2);
|
||||||
data.configdata = (FAR uint8_t *)&update_id;
|
data.configdata = (FAR uint8_t *)&update_id;
|
||||||
data.len = sizeof(update_id);
|
data.len = sizeof(update_id);
|
||||||
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_SETCONFIG, &data);
|
||||||
@ -2379,7 +2379,7 @@ static void test_nvs_gc_not_touched_expired_ate(struct mtdnvs_ctx_s *ctx)
|
|||||||
|
|
||||||
for (i = 0; i <= filling_id - 1; i++)
|
for (i = 0; i <= filling_id - 1; i++)
|
||||||
{
|
{
|
||||||
sprintf(data.name, "k%04x", i);
|
snprintf(data.name, sizeof(data.name), "k%04x", i);
|
||||||
data.configdata = (FAR uint8_t *)&data_read;
|
data.configdata = (FAR uint8_t *)&data_read;
|
||||||
data.len = sizeof(data_read);
|
data.len = sizeof(data_read);
|
||||||
ret = ioctl(fd, CFGDIOC_GETCONFIG, &data);
|
ret = ioctl(fd, CFGDIOC_GETCONFIG, &data);
|
||||||
|
@ -1126,7 +1126,7 @@ int main(int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
fscanf(fp, "%s", s2);
|
fscanf(fp, "%s", s2);
|
||||||
fscanf(fp, "%2c", s3);
|
fscanf(fp, "%2c", s3);
|
||||||
sprintf(s1, "%s%s", s2, s3);
|
snprintf(s1, sizeof(s1), "%s%s", s2, s3);
|
||||||
|
|
||||||
if (strcmp(s1, teststring) != 0)
|
if (strcmp(s1, teststring) != 0)
|
||||||
{
|
{
|
||||||
|
@ -91,7 +91,8 @@ static int smart_create_test_file(char *filename)
|
|||||||
{
|
{
|
||||||
g_line_pos[x] = ftell(fd);
|
g_line_pos[x] = ftell(fd);
|
||||||
|
|
||||||
sprintf(string, "This is line %d at offset %d\n", x, g_line_pos[x]);
|
snprintf(string, sizeof(string),
|
||||||
|
"This is line %d at offset %d\n", x, g_line_pos[x]);
|
||||||
g_line_len[x] = strlen(string);
|
g_line_len[x] = strlen(string);
|
||||||
fprintf(fd, "%s", string);
|
fprintf(fd, "%s", string);
|
||||||
|
|
||||||
@ -148,8 +149,9 @@ static int smart_seek_test(char *filename)
|
|||||||
fread(readstring, 1, g_line_len[index], fd);
|
fread(readstring, 1, g_line_len[index], fd);
|
||||||
readstring[g_line_len[index]] = '\0';
|
readstring[g_line_len[index]] = '\0';
|
||||||
|
|
||||||
sprintf(cmpstring, "This is line %d at offset %d\n",
|
snprintf(cmpstring, sizeof(cmpstring),
|
||||||
index, g_line_pos[index]);
|
"This is line %d at offset %d\n",
|
||||||
|
index, g_line_pos[index]);
|
||||||
|
|
||||||
if (strcmp(readstring, cmpstring) != 0)
|
if (strcmp(readstring, cmpstring) != 0)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user