winedbg: maintenance
Eric Pouech
eric.pouech at wanadoo.fr
Sat Feb 1 07:34:42 CST 2003
this patch should be (mostly) a no op in gdb proxy part:
- source code factorization
- replacing sprintf by snprintf for sake of mind
(NB: next patch will include the rest of sprintf => snprintf conversion
in winedbg)
A+
--
Eric Pouech
-------------- next part --------------
Name: wd_pxy
ChangeLog: - translated sprintf calls into snprintf
- added helper for sending strings in hex form
License: X11
GenDate: 2003/02/01 13:31:35 UTC
ModifiedFiles: programs/winedbg/gdbproxy.c
AddedFiles:
Index: programs/winedbg/gdbproxy.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/programs/winedbg/gdbproxy.c,v
retrieving revision 1.5
diff -u -u -r1.5 gdbproxy.c
--- programs/winedbg/gdbproxy.c 23 Jan 2003 21:32:35 -0000 1.5
+++ programs/winedbg/gdbproxy.c 1 Feb 2003 10:48:14 -0000
@@ -791,7 +791,7 @@
strcpy(buffer, "Running");
}
else
- sprintf(buffer, "Terminated (%lu)", status);
+ snprintf(buffer, len, "Terminated (%lu)", status);
switch (GetPriorityClass(gdbctx->process->handle))
{
@@ -833,12 +833,12 @@
{
case -1: break;
case 0: strcpy(buffer, "Running"); break;
- default: sprintf(buffer, "Suspended (%lu)", status - 1);
+ default: snprintf(buffer, len, "Suspended (%lu)", status - 1);
}
ResumeThread(thd->handle);
}
else
- sprintf(buffer, "Terminated (exit code = %lu)", status);
+ snprintf(buffer, len, "Terminated (exit code = %lu)", status);
}
else
{
@@ -854,7 +854,7 @@
case THREAD_PRIORITY_IDLE: strcat(buffer, ", priority idle"); break;
case THREAD_PRIORITY_NORMAL: strcat(buffer, ", priority normal"); break;
case THREAD_PRIORITY_TIME_CRITICAL: strcat(buffer, ", priority time-critical"); break;
- default: sprintf(buffer + strlen(buffer), ", priority = %d", prio);
+ default: snprintf(buffer + strlen(buffer), len - strlen(buffer), ", priority = %d", prio);
}
assert(strlen(buffer) < len);
}
@@ -883,6 +883,11 @@
gdbctx->out_len += len * 2;
}
+static inline void packet_reply_hex_to_str(struct gdb_context* gdbctx, const char* src)
+{
+ packet_reply_hex_to(gdbctx, src, strlen(src));
+}
+
static void packet_reply_val(struct gdb_context* gdbctx, unsigned long val, int len)
{
int i, shift;
@@ -1281,11 +1286,12 @@
packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O');
- sprintf(buffer, "%*s%04x%*s%-17.17s %08lx %08lx %.14s\n",
- indent, "", (UINT)hWnd, 13 - indent, "",
- clsName, GetWindowLong(hWnd, GWL_STYLE),
- GetWindowLong(hWnd, GWL_WNDPROC), wndName);
- packet_reply_hex_to(gdbctx, buffer, strlen(buffer));
+ snprintf(buffer, sizeof(buffer),
+ "%*s%04x%*s%-17.17s %08lx %08lx %.14s\n",
+ indent, "", (UINT)hWnd, 13 - indent, "",
+ clsName, GetWindowLong(hWnd, GWL_STYLE),
+ GetWindowLong(hWnd, GWL_WNDPROC), wndName);
+ packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx);
if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
@@ -1301,9 +1307,10 @@
* marking the end of the output */
packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O');
- sprintf(buffer, "%-16.16s %-17.17s %-8.8s %s\n",
- "hwnd", "Class Name", " Style", " WndProc Text");
- packet_reply_hex_to(gdbctx, buffer, strlen(buffer));
+ snprintf(buffer, sizeof(buffer),
+ "%-16.16s %-17.17s %-8.8s %s\n",
+ "hwnd", "Class Name", " Style", " WndProc Text");
+ packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx);
/* FIXME: could also add a pmt to this command in str... */
@@ -1330,9 +1337,10 @@
packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O');
- sprintf(buffer, " %-8.8s %-8.8s %-8.8s %s\n",
- "pid", "threads", "parent", "executable" );
- packet_reply_hex_to(gdbctx, buffer, strlen(buffer));
+ snprintf(buffer, sizeof(buffer),
+ " %-8.8s %-8.8s %-8.8s %s\n",
+ "pid", "threads", "parent", "executable" );
+ packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx);
while (ok)
@@ -1341,10 +1349,11 @@
if (entry.th32ProcessID == gdbctx->process->pid) deco = '>';
packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O');
- sprintf(buffer, "%c%08lx %-8ld %08lx '%s'\n",
- deco, entry.th32ProcessID, entry.cntThreads,
- entry.th32ParentProcessID, entry.szExeFile);
- packet_reply_hex_to(gdbctx, buffer, strlen(buffer));
+ snprintf(buffer, sizeof(buffer),
+ "%c%08lx %-8ld %08lx '%s'\n",
+ deco, entry.th32ProcessID, entry.cntThreads,
+ entry.th32ParentProcessID, entry.szExeFile);
+ packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx);
ok = Process32Next(snap, &entry);
}
@@ -1365,8 +1374,7 @@
* marking the end of the output */
packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O');
- sprintf(buffer, "Address Size State Type RWX\n");
- packet_reply_hex_to(gdbctx, buffer, strlen(buffer));
+ packet_reply_hex_to_str(gdbctx, "Address Size State Type RWX\n");
packet_reply_close(gdbctx);
while (VirtualQueryEx(gdbctx->process->handle, addr, &mbi, sizeof(mbi)) >= sizeof(mbi))
@@ -1405,10 +1413,11 @@
prot[0] = '\0';
}
packet_reply_open(gdbctx);
- sprintf(buffer, "%08lx %08lx %s %s %s\n",
- (DWORD)addr, mbi.RegionSize, state, type, prot);
+ snprintf(buffer, sizeof(buffer),
+ "%08lx %08lx %s %s %s\n",
+ (DWORD)addr, mbi.RegionSize, state, type, prot);
packet_reply_catc(gdbctx, 'O');
- packet_reply_hex_to(gdbctx, buffer, strlen(buffer));
+ packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx);
if (addr + mbi.RegionSize < addr) /* wrap around ? */
@@ -1425,12 +1434,12 @@
if (len == 0)
{
- sprintf(buffer, "trace=%x\n", gdbctx->trace);
+ snprintf(buffer, sizeof(buffer), "trace=%x\n", gdbctx->trace);
}
else if (len >= 2 && str[0] == '=')
{
unsigned val = atoi(&str[1]);
- sprintf(buffer, "trace: %x => %x\n", gdbctx->trace, val);
+ snprintf(buffer, sizeof(buffer), "trace: %x => %x\n", gdbctx->trace, val);
gdbctx->trace = val;
}
else
@@ -1440,7 +1449,7 @@
return;
}
packet_reply_open(gdbctx);
- packet_reply_hex_to(gdbctx, buffer, strlen(buffer));
+ packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx);
}
@@ -1474,9 +1483,9 @@
le.BaseLow + ofs;
/* error */
else linear = 0;
- sprintf(buffer, "0x%x", linear);
+ snprintf(buffer, sizeof(buffer), "0x%x", linear);
packet_reply_open(gdbctx);
- packet_reply_hex_to(gdbctx, buffer, strlen(buffer));
+ packet_reply_hex_to_str(gdbctx, buffer);
packet_reply_close(gdbctx);
}
#endif
@@ -1549,7 +1558,7 @@
packet_reply_open(gdbctx);
packet_reply_catc(gdbctx, 'O');
get_process_info(gdbctx, result, sizeof(result));
- packet_reply_hex_to(gdbctx, result, strlen(result));
+ packet_reply_hex_to_str(gdbctx, result);
packet_reply_close(gdbctx);
return packet_done;
}
@@ -1589,9 +1598,10 @@
if (gdbctx->wine_segs[0] == 0 && gdbctx->wine_segs[1] == 0 &&
gdbctx->wine_segs[2] == 0)
return packet_error;
- sprintf(buf, "Text=%08lx;Data=%08lx;Bss=%08lx",
- gdbctx->wine_segs[0], gdbctx->wine_segs[1],
- gdbctx->wine_segs[2]);
+ snprintf(buf, sizeof(buf),
+ "Text=%08lx;Data=%08lx;Bss=%08lx",
+ gdbctx->wine_segs[0], gdbctx->wine_segs[1],
+ gdbctx->wine_segs[2]);
return packet_reply(gdbctx, buf, -1);
}
break;
@@ -1619,7 +1629,7 @@
if (end == NULL) break;
get_thread_info(gdbctx, tid, result, sizeof(result));
packet_reply_open(gdbctx);
- packet_reply_hex_to(gdbctx, result, strlen(result));
+ packet_reply_hex_to_str(gdbctx, result);
packet_reply_close(gdbctx);
return packet_done;
}
More information about the wine-patches
mailing list