[dlls/iphlpapi/*] Strncpy elimination.
Peter Berg Larsen
pebl at math.ku.dk
Sun Mar 27 11:59:50 CST 2005
I have been checking the usage of strncpy, replacing where apropriate with
a memcpy or lstrcpyn[AW]. The first raw diff was 100kb, so there is bound
to be one or two slips. These are the first batch which I found to be
obvious, correct, and didnt need a special comment. Note with correct I
mean if there was a \0 bug before then it still there.
Changelog:
Janitorial Task: Check the usage of strncpy/strncpyW.
Index: dlls/iphlpapi/ifenum.c
===================================================================
RCS file: /home/wine/wine/dlls/iphlpapi/ifenum.c,v
retrieving revision 1.13
diff -u -r1.13 ifenum.c
--- dlls/iphlpapi/ifenum.c 24 Mar 2005 21:01:38 -0000 1.13
+++ dlls/iphlpapi/ifenum.c 26 Mar 2005 09:40:31 -0000
@@ -191,8 +191,7 @@
if (name) {
struct ifreq ifr;
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
- ifr.ifr_name[IFNAMSIZ-1] = '\0';
+ lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
if (ioctl(fd, SIOCGIFFLAGS, &ifr) == 0)
ret = ifr.ifr_flags & IFF_LOOPBACK;
}
@@ -245,8 +244,7 @@
/* look for new slot */
for (ndx = 0; !stored && ndx < map->numAllocated; ndx++) {
if (!map->table[ndx].inUse) {
- strncpy(map->table[ndx].name, name, IFNAMSIZ);
- map->table[ndx].name[IFNAMSIZ-1] = '\0';
+ lstrcpynA(map->table[ndx].name, name, IFNAMSIZ);
map->table[ndx].inUse = TRUE;
stored = TRUE;
if (ndx >= map->nextAvailable)
@@ -467,8 +465,7 @@
if (fd != -1) {
struct ifreq ifr;
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
- ifr.ifr_name[IFNAMSIZ-1] = '\0';
+ lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0)
memcpy(&ret, ifr.ifr_addr.sa_data + 2, sizeof(DWORD));
close(fd);
@@ -499,8 +496,7 @@
if (fd != -1) {
struct ifreq ifr;
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
- ifr.ifr_name[IFNAMSIZ-1] = '\0';
+ lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
if (ioctl(fd, SIOCGIFBRDADDR, &ifr) == 0)
memcpy(&ret, ifr.ifr_addr.sa_data + 2, sizeof(DWORD));
close(fd);
@@ -531,8 +527,7 @@
if (fd != -1) {
struct ifreq ifr;
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
- ifr.ifr_name[IFNAMSIZ-1] = '\0';
+ lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
if (ioctl(fd, SIOCGIFNETMASK, &ifr) == 0)
memcpy(&ret, ifr.ifr_addr.sa_data + 2, sizeof(DWORD));
close(fd);
@@ -568,8 +563,7 @@
struct ifreq ifr;
memset(&ifr, 0, sizeof(struct ifreq));
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
- ifr.ifr_name[IFNAMSIZ-1] = '\0';
+ lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
if ((ioctl(fd, SIOCGIFHWADDR, &ifr)))
ret = ERROR_INVALID_DATA;
else {
@@ -813,8 +807,7 @@
if (fd != -1) {
struct ifreq ifr;
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
- ifr.ifr_name[IFNAMSIZ-1] = '\0';
+ lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
if ((ioctl(fd, SIOCGIFMTU, &ifr)))
ret = ERROR_INVALID_DATA;
else {
@@ -855,8 +848,7 @@
if (fd != -1) {
struct ifreq ifr;
- strncpy(ifr.ifr_name, name, IFNAMSIZ);
- ifr.ifr_name[IFNAMSIZ-1] = '\0';
+ lstrcpynA(ifr.ifr_name, name, IFNAMSIZ);
if ((ioctl(fd, SIOCGIFFLAGS, &ifr)))
ret = ERROR_INVALID_DATA;
else {
@@ -940,8 +932,7 @@
iAddr.s_addr = addr;
/* extra-anal, just to make auditors happy */
- strncpy(string, inet_ntoa(iAddr), 16);
- string[16] = '\0';
+ lstrcpynA(string, inet_ntoa(iAddr), sizeof(string));
}
return string;
}
Index: dlls/iphlpapi/iphlpapi_main.c
===================================================================
RCS file: /home/wine/wine/dlls/iphlpapi/iphlpapi_main.c,v
retrieving revision 1.14
diff -u -r1.14 iphlpapi_main.c
--- dlls/iphlpapi/iphlpapi_main.c 24 Mar 2005 21:01:38 -0000
1.14
+++ dlls/iphlpapi/iphlpapi_main.c 26 Mar 2005 09:40:33 -0000
@@ -643,10 +643,9 @@
DWORD addrLen = sizeof(ptr->Address), type;
/* on Win98 this is left empty, but whatever */
- strncpy(ptr->AdapterName,
+ lstrcpynA(ptr->AdapterName,
getInterfaceNameByIndex(table->indexes[ndx]),
- sizeof(ptr->AdapterName));
- ptr->AdapterName[MAX_ADAPTER_NAME_LENGTH] = '\0';
+ MAX_ADAPTER_NAME_LENGTH+1);
getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen,
ptr->Address, &type);
/* MS defines address length and type as UINT in some places and
More information about the wine-patches
mailing list