[dlls/dbghelp/type.c] strncpy elimination.

Peter Berg Larsen pebl at math.ku.dk
Sun Mar 27 12:40:27 CST 2005


I am puzzled at use of ->NameLen in this place. I would expect it
represent the string length without \0 judging from the else part.
But the NameLen in the if reflect the original length, with the \0
included, and before strncpy.

Changelog:
	Eliminate a strncpy, and replace it with an memcpy.
	This also corrects ->NameLen may be set too high.


Index: dlls/dbghelp/type.c
===================================================================
RCS file: /home/wine/wine/dlls/dbghelp/type.c,v
retrieving revision 1.11
diff -u -r1.11 type.c
--- dlls/dbghelp/type.c	9 Jan 2005 16:42:53 -0000	1.11
+++ dlls/dbghelp/type.c	26 Mar 2005 09:40:10 -0000
@@ -398,11 +398,12 @@
         tmp = symt_get_name(type);
         if (tmp)
         {
-            sym_info->NameLen = strlen(tmp) + 1;
-            strncpy(sym_info->Name, tmp, min(sym_info->NameLen, sym_info->MaxNameLen));
-            sym_info->Name[sym_info->MaxNameLen - 1] = '\0';
-        }
-        else sym_info->Name[sym_info->NameLen = 0] = '\0';
+            sym_info->NameLen = min(strlen(sym_info->Name),sym_info->MaxNameLen-1);
+            memcpy(sym_info->Name, tmp, sym_info->NameLen);
+            sym_info->Name[sym_info->NameLen] = '\0';
+        }
+        else
+	    sym_info->Name[sym_info->NameLen = 0] = '\0';
         if (!EnumSymbolsCallback(sym_info, sym_info->Size, UserContext)) break;
     }
     return TRUE;





More information about the wine-patches mailing list