[dlls/dbghelp/dbghelp.c module.c symbol.c] Strncpy elimation.
Peter Berg Larsen
pebl at math.ku.dk
Sun Mar 27 11:46:06 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/dbghelp/dbghelp.c
===================================================================
RCS file: /home/wine/wine/dlls/dbghelp/dbghelp.c,v
retrieving revision 1.9
diff -u -r1.9 dbghelp.c
--- dlls/dbghelp/dbghelp.c 7 Mar 2005 12:24:02 -0000 1.9
+++ dlls/dbghelp/dbghelp.c 26 Mar 2005 09:40:07 -0000
@@ -126,8 +126,7 @@
struct process* pcs = process_find_by_handle(hProcess);
if (!pcs) return FALSE;
- strncpy(szSearchPath, pcs->search_path, SearchPathLength);
- szSearchPath[SearchPathLength - 1] = '\0';
+ lstrcpynA(szSearchPath, pcs->search_path, SearchPathLength);
return TRUE;
}
Index: dlls/dbghelp/module.c
===================================================================
RCS file: /home/wine/wine/dlls/dbghelp/module.c,v
retrieving revision 1.9
diff -u -r1.9 module.c
--- dlls/dbghelp/module.c 1 Mar 2005 10:39:49 -0000 1.9
+++ dlls/dbghelp/module.c 26 Mar 2005 09:40:07 -0000
@@ -42,8 +42,7 @@
*ptr != '/' && *ptr != '\\' && ptr >= in;
ptr--);
if (ptr < in || *ptr == '/' || *ptr == '\\') ptr++;
- strncpy(out, ptr, size);
- out[size - 1] = '\0';
+ lstrcpynA(out, ptr, size);
len = strlen(out);
if (len > 4 &&
(!strcasecmp(&out[len - 4], ".dll") || !strcasecmp(&out[len - 4], ".exe")))
@@ -51,7 +50,7 @@
else if (((len > 12 && out[len - 13] == '/') || len == 12) &&
(!strcasecmp(out + len - 12, "wine-pthread") ||
!strcasecmp(out + len - 12, "wine-kthread")))
- strcpy(out, "<wine-loader>");
+ lstrcpynA(out, "<wine-loader>",size);
else
{
if (len > 7 &&
@@ -96,9 +95,7 @@
module->module.ImageSize = size;
module_fill_module(name, module->module.ModuleName, sizeof(module->module.ModuleName));
module->module.ImageName[0] = '\0';
- strncpy(module->module.LoadedImageName, name,
- sizeof(module->module.LoadedImageName));
- module->module.LoadedImageName[sizeof(module->module.LoadedImageName) - 1] = '\0';
+ lstrcpynA(module->module.LoadedImageName, name, sizeof(module->module.LoadedImageName));
module->module.SymType = SymNone;
module->module.NumSyms = 0;
module->module.TimeDateStamp = stamp;
@@ -360,13 +357,8 @@
* of ImageName. Overwrite it, if we have better information
*/
if (ModuleName)
- {
- strncpy(module->module.ModuleName, ModuleName,
- sizeof(module->module.ModuleName));
- module->module.ModuleName[sizeof(module->module.ModuleName) - 1] = '\0';
- }
- strncpy(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
- module->module.ImageName[sizeof(module->module.ImageName) - 1] = '\0';
+ lstrcpynA(module->module.ModuleName, ModuleName, sizeof(module->module.ModuleName));
+ lstrcpynA(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
return module->module.BaseOfImage;
}
Index: dlls/dbghelp/symbol.c
===================================================================
RCS file: /home/wine/wine/dlls/dbghelp/symbol.c,v
retrieving revision 1.15
diff -u -r1.15 symbol.c
--- dlls/dbghelp/symbol.c 31 Jan 2005 11:35:00 -0000 1.15
+++ dlls/dbghelp/symbol.c 26 Mar 2005 09:40:09 -0000
@@ -536,7 +536,7 @@
sym_info->MaxNameLen, UNDNAME_COMPLETE) == 0))
{
sym_info->NameLen = min(strlen(name), sym_info->MaxNameLen - 1);
- strncpy(sym_info->Name, name, sym_info->NameLen);
+ memcpy(sym_info->Name, name, sym_info->NameLen);
sym_info->Name[sym_info->NameLen] = '\0';
}
}
@@ -916,8 +916,7 @@
Symbol->Size = si->Size;
Symbol->Flags = si->Flags;
len = min(Symbol->MaxNameLength, si->MaxNameLen);
- strncpy(Symbol->Name, si->Name, len);
- Symbol->Name[len - 1] = '\0';
+ lstrcpynA(Symbol->Name, si->Name, len);
return TRUE;
}
@@ -992,8 +991,7 @@
Symbol->Size = si->Size;
Symbol->Flags = si->Flags;
len = min(Symbol->MaxNameLength, si->MaxNameLen);
- strncpy(Symbol->Name, si->Name, len);
- Symbol->Name[len - 1] = '\0';
+ lstrcpynA(Symbol->Name, si->Name, len);
return TRUE;
}
More information about the wine-patches
mailing list