[dlls/user/edit.c] Strncpy elimination.
Peter Berg Larsen
pebl at math.ku.dk
Sun Mar 27 12:16:21 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/user/edit.c
===================================================================
RCS file: /home/wine/wine/dlls/user/edit.c,v
retrieving revision 1.22
diff -u -r1.22 edit.c
--- dlls/user/edit.c 23 Mar 2005 13:15:18 -0000 1.22
+++ dlls/user/edit.c 26 Mar 2005 09:41:28 -0000
@@ -3049,11 +3049,10 @@
if (e != s) {
/* there is something to be deleted */
TRACE("deleting stuff.\n");
- bufl = e - s;
- buf = HeapAlloc(GetProcessHeap(), 0, (bufl + 1) * sizeof(WCHAR));
+ bufl = e - s + 1;
+ buf = HeapAlloc(GetProcessHeap(), 0, bufl * sizeof(WCHAR));
if (!buf) return;
- strncpyW(buf, es->text + s, bufl);
- buf[bufl] = 0; /* ensure 0 termination */
+ lstrcpynW(buf, es->text + s, bufl); /* ensure 0 termination */
/* now delete */
strcpyW(es->text + s, es->text + e);
}
@@ -3113,8 +3112,7 @@
if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
/* undo-buffer is extended to the right */
EDIT_MakeUndoFit(es, utl + e - s);
- strncpyW(es->undo_text + utl, buf, e - s + 1);
- (es->undo_text + utl)[e - s] = 0; /* ensure 0 termination */
+ lstrcpynW(es->undo_text + utl, buf, e - s
+ 1);
} else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
/* undo-buffer is extended to the left */
EDIT_MakeUndoFit(es, utl + e - s);
@@ -3126,8 +3124,7 @@
} else {
/* new undo-buffer */
EDIT_MakeUndoFit(es, e - s);
- strncpyW(es->undo_text, buf, e - s + 1);
- es->undo_text[e - s] = 0; /* ensure 0 termination */
+ lstrcpynW(es->undo_text, buf, e - s + 1);
es->undo_position = s;
}
/* any deletion makes the old insertion-undo invalid */
@@ -3932,13 +3929,14 @@
INT e = max(es->selection_start, es->selection_end);
HGLOBAL hdst;
LPWSTR dst;
+ DWORD len;
if (e == s) return;
- hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (DWORD)(e - s + 1) * sizeof(WCHAR));
+ len = e - s + 1;
+ hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, len * sizeof(WCHAR));
dst = GlobalLock(hdst);
- strncpyW(dst, es->text + s, e - s);
- dst[e - s] = 0; /* ensure 0 termination */
+ lstrcpynW(dst, es->text + s, len);
TRACE("%s\n", debugstr_w(dst));
GlobalUnlock(hdst);
OpenClipboard(es->hwndSelf);
More information about the wine-patches
mailing list