[dlls/dbghelp/type.c] Elimination of strncpy + bug

Peter Berg Larsen pebl at math.ku.dk
Fri Apr 15 16:48:30 CDT 2005


From
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/symbol_info_str.asp
>>>
NameLen:
Length of the name, in characters, not including the null-terminating character.

MaxNameLen:
Size of the Name buffer, in characters. If this member is 0, the Name
member is not used.

Name:
Null-terminated string that specifies the name of the symbol. The name can
be undecorated if the SYMOPT_UNDNAME option is used with the SymSetOptions
function.
<<<

The old code seemed to include '\0' to the NameLen, and returned to large
buffer if was to small. Or is the latter on purpose?


Changelog:
       Eliminate strncpy and correct some NameLen bugs.


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 15 Apr 2005 20:13:51 -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(tmp),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