From be15b141e0dddd9f41e464ca98aef1b05b28cf6b Mon Sep 17 00:00:00 2001 From: blueswir1 Date: Sat, 25 Oct 2008 11:21:28 +0000 Subject: [PATCH] Replace uses of strncpy (a GNU extension) with Qemu pstrcpy git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5531 c046a42c-6fe2-441c-8c8c-71466251a162 --- block-vmdk.c | 2 +- block-vvfat.c | 2 +- hw/bt-hci.c | 2 +- linux-user/syscall.c | 2 +- slirp/udp.c | 4 ++-- vl.c | 4 ++-- vnc.c | 3 ++- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/block-vmdk.c b/block-vmdk.c index c49b6719..2a257b6f 100644 --- a/block-vmdk.c +++ b/block-vmdk.c @@ -344,7 +344,7 @@ static int vmdk_parent_open(BlockDriverState *bs, const char * filename) if ((end_name - p_name) > sizeof (s->hd->backing_file) - 1) return -1; - strncpy(s->hd->backing_file, p_name, end_name - p_name); + pstrcpy(s->hd->backing_file, end_name - p_name, p_name); if (stat(s->hd->backing_file, &file_buf) != 0) { path_combine(parent_img_name, sizeof(parent_img_name), filename, s->hd->backing_file); diff --git a/block-vvfat.c b/block-vvfat.c index 79804a71..1db2c8c8 100644 --- a/block-vvfat.c +++ b/block-vvfat.c @@ -625,7 +625,7 @@ static inline direntry_t* create_short_and_long_name(BDRVVVFATState* s, entry=array_get_next(&(s->directory)); memset(entry->name,0x20,11); - strncpy((char*)entry->name,filename,i); + pstrcpy((char*)entry->name, i, filename); if(j > 0) for (i = 0; i < 3 && filename[j+1+i]; i++) diff --git a/hw/bt-hci.c b/hw/bt-hci.c index 725e32c9..714e7267 100644 --- a/hw/bt-hci.c +++ b/hw/bt-hci.c @@ -1385,7 +1385,7 @@ static inline void bt_hci_event_complete_read_local_name(struct bt_hci_s *hci) params.status = HCI_SUCCESS; memset(params.name, 0, sizeof(params.name)); if (hci->device.lmp_name) - strncpy(params.name, hci->device.lmp_name, sizeof(params.name)); + pstrcpy(params.name, sizeof(params.name), hci->device.lmp_name); bt_hci_event_complete(hci, ¶ms, READ_LOCAL_NAME_RP_SIZE); } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c1301ee5..29254a27 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4993,7 +4993,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, if (tnamelen > 256) tnamelen = 256; /* XXX: may not be correct */ - strncpy(tde->d_name, de->d_name, tnamelen); + pstrcpy(tde->d_name, tnamelen, de->d_name); de = (struct linux_dirent *)((char *)de + reclen); len -= reclen; tde = (struct target_dirent *)((char *)tde + treclen); diff --git a/slirp/udp.c b/slirp/udp.c index 0583d7e9..8030326a 100644 --- a/slirp/udp.c +++ b/slirp/udp.c @@ -475,14 +475,14 @@ struct cu_header { type = omsg->type; OTOSIN(omsg, ctl_addr)->sin_port = addr.sin_port; OTOSIN(omsg, ctl_addr)->sin_addr = our_addr; - strncpy(omsg->l_name, getlogin(), NAME_SIZE_OLD); + pstrcpy(omsg->l_name, NAME_SIZE_OLD, getlogin()); } else { /* new talk */ omsg = (CTL_MSG_OLD *) buff; nmsg = mtod(m, CTL_MSG *); type = nmsg->type; OTOSIN(nmsg, ctl_addr)->sin_port = addr.sin_port; OTOSIN(nmsg, ctl_addr)->sin_addr = our_addr; - strncpy(nmsg->l_name, getlogin(), NAME_SIZE_OLD); + pstrcpy(nmsg->l_name, NAME_SIZE_OLD, getlogin()); } if (type == LOOK_UP) diff --git a/vl.c b/vl.c index 1fb47492..b96735e2 100644 --- a/vl.c +++ b/vl.c @@ -4446,7 +4446,7 @@ int tap_alloc(char *dev, size_t dev_size) syslog(LOG_ERR, "Can't get flags\n"); snprintf (actual_name, 32, "tap%d", ppa); - strncpy (ifr.lifr_name, actual_name, sizeof (ifr.lifr_name)); + pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name); ifr.lifr_ppa = ppa; /* Assign ppa according to the unit number returned by tun device */ @@ -4489,7 +4489,7 @@ int tap_alloc(char *dev, size_t dev_size) close (if_fd); memset(&ifr, 0x0, sizeof(ifr)); - strncpy (ifr.lifr_name, actual_name, sizeof (ifr.lifr_name)); + pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name); ifr.lifr_ip_muxid = ip_muxid; ifr.lifr_arp_muxid = arp_muxid; diff --git a/vnc.c b/vnc.c index 266460ff..9df4dbe1 100644 --- a/vnc.c +++ b/vnc.c @@ -2337,7 +2337,8 @@ int vnc_display_open(DisplayState *ds, const char *display) if (start && (!end || (start < end))) { int len = end ? end-(start+1) : strlen(start+1); char *path = qemu_malloc(len+1); - strncpy(path, start+1, len); + + pstrcpy(path, len, start + 1); path[len] = '\0'; VNC_DEBUG("Trying certificate path '%s'\n", path); if (vnc_set_x509_credential_dir(vs, path) < 0) { -- 2.39.5