Skip to content

Commit 325f395

Browse files
xiaoxiang781216jerpelea
authored andcommitted
Replace all strncpy with strlcpy
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent 6f6fce9 commit 325f395

File tree

7 files changed

+31
-35
lines changed

7 files changed

+31
-35
lines changed

arch/sim/src/sim/sim_rptun.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ int sim_rptun_init(const char *shmemname, const char *cpuname, bool master)
262262

263263
dev->master = master;
264264
dev->rptun.ops = &g_sim_rptun_ops;
265-
strncpy(dev->cpuname, cpuname, RPMSG_NAME_SIZE);
266-
strncpy(dev->shmemname, shmemname, RPMSG_NAME_SIZE);
265+
strlcpy(dev->cpuname, cpuname, RPMSG_NAME_SIZE);
266+
strlcpy(dev->shmemname, shmemname, RPMSG_NAME_SIZE);
267267
list_add_tail(&g_dev_list, &dev->node);
268268

269269
ret = rptun_initialize(&dev->rptun);

arch/xtensa/src/esp32/esp32_himem_chardev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ int himem_chardev_register(char *name, size_t size)
314314

315315
dev->size = size;
316316

317-
strncpy(dev->name, name, 32);
317+
strlcpy(dev->name, name, 32);
318318
ret = esp_himem_alloc(dev->size, &dev->mem_handle);
319319
if (ret != 0)
320320
{

boards/arm/imxrt/imxrt1064-evk/src/imxrt_progmem.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ static int init_ota_partitions(void)
186186
const struct ota_partition_s *part = &g_ota_partition_table[i];
187187
mtd = progmem_alloc_mtdpart(part->offset, part->size);
188188

189-
strncpy(path, (char *)part->devpath, PARTITION_LABEL_LEN);
190-
path[PARTITION_LABEL_LEN] = '\0';
189+
strlcpy(path, (char *)part->devpath, PARTITION_LABEL_LEN);
191190

192191
finfo("INFO: [label]: %s\n", path);
193192
finfo("INFO: [offset]: 0x%08" PRIx32 "\n", part->offset);

boards/arm/stm32h7/nucleo-h743zi/src/stm32_progmem.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ static int init_ota_partitions(void)
187187
const struct ota_partition_s *part = &g_ota_partition_table[i];
188188
mtd = progmem_alloc_mtdpart(part->offset, part->size);
189189

190-
strncpy(path, (char *)part->devpath, PARTITION_LABEL_LEN);
191-
path[PARTITION_LABEL_LEN] = '\0';
190+
strlcpy(path, (char *)part->devpath, PARTITION_LABEL_LEN);
192191

193192
finfo("INFO: [label]: %s\n", path);
194193
finfo("INFO: [offset]: 0x%08" PRIx32 "\n", part->offset);

drivers/modem/alt1250/altcom_hdlr.c

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,9 @@ int32_t altcombs_set_pdninfo(struct apicmd_pdnset_s *cmd_pdn,
790790
for (i = 0; i < lte_pdn->ipaddr_num; i++)
791791
{
792792
lte_pdn->address[i].ip_type = cmd_pdn->ip_address[i].iptype;
793-
strncpy(lte_pdn->address[i].address,
793+
strlcpy(lte_pdn->address[i].address,
794794
(FAR char *)cmd_pdn->ip_address[i].address,
795-
LTE_IPADDR_MAX_LEN - 1);
795+
LTE_IPADDR_MAX_LEN);
796796
}
797797

798798
lte_pdn->ims_register = cmd_pdn->imsregister == APICMD_PDN_IMS_REG ?
@@ -826,9 +826,9 @@ int32_t altcombs_set_pdninfo_v4(FAR struct apicmd_pdnset_v4_s *cmd_pdn,
826826
for (i = 0; i < lte_pdn->ipaddr_num; i++)
827827
{
828828
lte_pdn->address[i].ip_type = cmd_pdn->ip_address[i].iptype;
829-
strncpy(lte_pdn->address[i].address,
829+
strlcpy(lte_pdn->address[i].address,
830830
(FAR char *)cmd_pdn->ip_address[i].address,
831-
LTE_IPADDR_MAX_LEN - 1);
831+
LTE_IPADDR_MAX_LEN);
832832
}
833833

834834
lte_pdn->ims_register = cmd_pdn->imsregister;
@@ -1420,10 +1420,10 @@ static void getver_parse_response(FAR struct apicmd_cmddat_getverres_s *resp,
14201420
FAR lte_version_t *version)
14211421
{
14221422
memset(version, 0, sizeof(*version));
1423-
strncpy(version->bb_product,
1424-
(FAR const char *)resp->bb_product, LTE_VER_BB_PRODUCT_LEN - 1);
1425-
strncpy(version->np_package,
1426-
(FAR const char *)resp->np_package, LTE_VER_NP_PACKAGE_LEN - 1);
1423+
strlcpy(version->bb_product,
1424+
(FAR const char *)resp->bb_product, LTE_VER_BB_PRODUCT_LEN);
1425+
strlcpy(version->np_package,
1426+
(FAR const char *)resp->np_package, LTE_VER_NP_PACKAGE_LEN);
14271427
}
14281428

14291429
static void getpinset_parse_response(
@@ -1822,7 +1822,7 @@ static int copy_logfilename(FAR char *filename, size_t fnamelen,
18221822

18231823
if (pathlen <= fnamelen)
18241824
{
1825-
strncpy(filename, path, fnamelen);
1825+
strlcpy(filename, path, fnamelen);
18261826
}
18271827
else
18281828
{
@@ -1977,7 +1977,7 @@ static int32_t setpinlock_pkt_compose(FAR void **arg,
19771977
(FAR struct apicmd_cmddat_setpinlock_s *)pktbuf;
19781978

19791979
out->mode = *enable;
1980-
strncpy((FAR char *)out->pincode, pincode, sizeof(out->pincode));
1980+
strlcpy((FAR char *)out->pincode, pincode, sizeof(out->pincode));
19811981

19821982
size = sizeof(struct apicmd_cmddat_setpinlock_s);
19831983

@@ -2018,9 +2018,8 @@ static int32_t setpincode_pkt_compose(FAR void **arg,
20182018
out->chgtype = APICMD_SETPINCODE_CHGTYPE_PIN2;
20192019
}
20202020

2021-
strncpy((FAR char *)out->pincode, pincode, sizeof(out->pincode));
2022-
2023-
strncpy((FAR char *)out->newpincode, new_pincode, sizeof(out->newpincode));
2021+
strlcpy((FAR char *)out->pincode, pincode, sizeof(out->pincode));
2022+
strlcpy((FAR char *)out->newpincode, new_pincode, sizeof(out->newpincode));
20242023

20252024
size = sizeof(struct apicmd_cmddat_setpincode_s);
20262025

@@ -2051,11 +2050,11 @@ static int32_t enterpin_pkt_compose(FAR void **arg,
20512050
FAR struct apicmd_cmddat_enterpin_s *out =
20522051
(FAR struct apicmd_cmddat_enterpin_s *)pktbuf;
20532052

2054-
strncpy((FAR char *)out->pincode, pincode, sizeof(out->pincode));
2053+
strlcpy((FAR char *)out->pincode, pincode, sizeof(out->pincode));
20552054
if (new_pincode)
20562055
{
20572056
out->newpincodeuse = APICMD_ENTERPIN_NEWPINCODE_USE;
2058-
strncpy((FAR char *)out->newpincode,
2057+
strlcpy((FAR char *)out->newpincode,
20592058
new_pincode, sizeof(out->newpincode));
20602059
}
20612060
else
@@ -2531,14 +2530,14 @@ static int32_t actpdn_pkt_compose(FAR void **arg,
25312530
out->iptype = apn->ip_type;
25322531
out->authtype = apn->auth_type;
25332532

2534-
strncpy((FAR char *)out->apnname, (FAR const char *)apn->apn,
2533+
strlcpy((FAR char *)out->apnname, (FAR const char *)apn->apn,
25352534
sizeof(out->apnname));
25362535
if (apn->auth_type != LTE_APN_AUTHTYPE_NONE)
25372536
{
2538-
strncpy((FAR char *)out->username, (FAR const char *)apn->user_name,
2539-
sizeof(out->username));
2540-
strncpy((FAR char *)out->password, (FAR const char *)apn->password,
2541-
sizeof(out->password));
2537+
strlcpy((FAR char *)out->username, (FAR const char *)apn->user_name,
2538+
sizeof(out->username));
2539+
strlcpy((FAR char *)out->password, (FAR const char *)apn->password,
2540+
sizeof(out->password));
25422541
}
25432542

25442543
size = sizeof(struct apicmd_cmddat_activatepdn_s);
@@ -4248,7 +4247,7 @@ static int32_t getphone_pkt_parse(FAR struct alt1250_dev_s *dev,
42484247
}
42494248
}
42504249

4251-
strncpy(phoneno, (FAR const char *)in->phoneno, LTE_PHONENO_LEN);
4250+
strlcpy(phoneno, (FAR const char *)in->phoneno, LTE_PHONENO_LEN);
42524251
}
42534252

42544253
return 0;
@@ -4285,7 +4284,7 @@ static int32_t getimsi_pkt_parse(FAR struct alt1250_dev_s *dev,
42854284
}
42864285
}
42874286

4288-
strncpy(imsi, (FAR const char *)in->imsi, APICMD_IMSI_LEN);
4287+
strlcpy(imsi, (FAR const char *)in->imsi, APICMD_IMSI_LEN);
42894288
}
42904289

42914290
return 0;
@@ -4319,7 +4318,7 @@ static int32_t getimei_pkt_parse(FAR struct alt1250_dev_s *dev,
43194318
}
43204319
}
43214320

4322-
strncpy(imei, (FAR const char *)in->imei, LTE_IMEI_LEN);
4321+
strlcpy(imei, (FAR const char *)in->imei, LTE_IMEI_LEN);
43234322
}
43244323

43254324
return 0;
@@ -4455,7 +4454,7 @@ static int32_t getoper_pkt_parse(FAR struct alt1250_dev_s *dev,
44554454
}
44564455
}
44574456

4458-
strncpy(oper, (FAR const char *)in->oper, LTE_OPERATOR_LEN);
4457+
strlcpy(oper, (FAR const char *)in->oper, LTE_OPERATOR_LEN);
44594458
}
44604459
}
44614460
else if (altver == ALTCOM_VER4)
@@ -4482,7 +4481,7 @@ static int32_t getoper_pkt_parse(FAR struct alt1250_dev_s *dev,
44824481
}
44834482
}
44844483

4485-
strncpy(oper, (FAR const char *)in->oper, LTE_OPERATOR_LEN);
4484+
strlcpy(oper, (FAR const char *)in->oper, LTE_OPERATOR_LEN);
44864485
}
44874486
}
44884487

libs/libc/unistd/lib_swab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
****************************************************************************/
3434

3535
/****************************************************************************
36-
* Name: strncpy
36+
* Name: swab
3737
*
3838
* Description:
3939
* The swab() function will copy nbytes bytes, which are pointed to by

sched/pthread/pthread_create.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ static inline void pthread_tcb_setup(FAR struct pthread_tcb_s *ptcb,
9292
#if CONFIG_TASK_NAME_SIZE > 0
9393
/* Copy the pthread name into the TCB */
9494

95-
strncpy(ptcb->cmn.name, parent->name, CONFIG_TASK_NAME_SIZE);
96-
ptcb->cmn.name[CONFIG_TASK_NAME_SIZE] = '\0';
95+
strlcpy(ptcb->cmn.name, parent->name, CONFIG_TASK_NAME_SIZE);
9796
#endif /* CONFIG_TASK_NAME_SIZE */
9897

9998
/* For pthreads, args are strictly pass-by-value; that actual

0 commit comments

Comments
 (0)