[PATCH] kernel32: lstrlen does not call SetLastError.

Lei Zhang thestig at google.com
Wed Apr 28 19:29:54 CDT 2010


Hi,

Timur asked me to look into bug 22514 and it looks like all there is
to do is to remove the SetLastError() calls. I tested against Win XP
SP3. I'll test against Win9x when I get home.

Timur wondered why we don't add a NULL check to lstrlenA, and I know
AJ's reply will probably be: "it's a useless check." So in the spirit
of doing less work, we should remove the SetLastError call as well
since Windows doesn't do it.

Dmitry asked if any application depends on this behavior - of course
there aren't any. Why would any application depend on behavior that
doesn't exist?

- Lei
-------------- next part --------------
From f0a6fb4d56b39e569621de52601265e30979a80d Mon Sep 17 00:00:00 2001
From: Lei Zhang <thestig at google.com>
Date: Wed, 28 Apr 2010 16:13:20 -0700
Subject: [PATCH] kernel32: lstrlen does not call SetLastError.

---
 dlls/kernel32/string.c          |    2 -
 dlls/kernel32/tests/Makefile.in |    1 +
 dlls/kernel32/tests/string.c    |   77 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 2 deletions(-)
 create mode 100644 dlls/kernel32/tests/string.c

diff --git a/dlls/kernel32/string.c b/dlls/kernel32/string.c
index 120c868..6dcb0e3 100644
--- a/dlls/kernel32/string.c
+++ b/dlls/kernel32/string.c
@@ -195,7 +195,6 @@ INT WINAPI lstrlenA( LPCSTR str )
     }
     __EXCEPT_PAGE_FAULT
     {
-        SetLastError( ERROR_INVALID_PARAMETER );
         return 0;
     }
     __ENDTRY
@@ -215,7 +214,6 @@ INT WINAPI lstrlenW( LPCWSTR str )
     }
     __EXCEPT_PAGE_FAULT
     {
-        SetLastError( ERROR_INVALID_PARAMETER );
         return 0;
     }
     __ENDTRY
diff --git a/dlls/kernel32/tests/Makefile.in b/dlls/kernel32/tests/Makefile.in
index ed2d6e6..9f65652 100644
--- a/dlls/kernel32/tests/Makefile.in
+++ b/dlls/kernel32/tests/Makefile.in
@@ -31,6 +31,7 @@ C_SRCS = \
 	process.c \
 	profile.c \
 	resource.c \
+	string.c \
 	sync.c \
 	thread.c \
 	time.c \
diff --git a/dlls/kernel32/tests/string.c b/dlls/kernel32/tests/string.c
new file mode 100644
index 0000000..a1e62e6
--- /dev/null
+++ b/dlls/kernel32/tests/string.c
@@ -0,0 +1,77 @@
+/*
+ * String function tests
+ *
+ * Copyright 2010 Google (Lei Zhang)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+#include <windef.h>
+#include <winbase.h>
+
+#include "wine/test.h"
+
+#define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected 0x%08x, got 0x%08x\n", (EXPECTED), (GOT))
+
+static void test_strlen(void)
+{
+    INT ret;
+    DWORD error;
+    static const CHAR str[] = "test string";
+    static const WCHAR strW[] = { 't','e','s','t',' ','s','t','r','i','n','g',0 };
+    const INT len = 11;
+
+    SetLastError(0xdeadbeef);
+    ret = lstrlenW(NULL);
+    error = GetLastError();
+    expect(0, ret);
+    expect(0xdeadbeef, error);
+
+    SetLastError(0xdeadbeef);
+    ret = lstrlenA(NULL);
+    error = GetLastError();
+    expect(0, ret);
+    expect(0xdeadbeef, error);
+
+    SetLastError(0xdeadbeef);
+    ret = lstrlenW((LPCWSTR)1);
+    error = GetLastError();
+    expect(0, ret);
+    expect(0xdeadbeef, error);
+
+    SetLastError(0xdeadbeef);
+    ret = lstrlenA((LPCSTR)1);
+    error = GetLastError();
+    expect(0, ret);
+    expect(0xdeadbeef, error);
+
+    SetLastError(0xdeadbeef);
+    ret = lstrlenW(strW);
+    error = GetLastError();
+    expect(len, ret);
+    expect(0xdeadbeef, error);
+
+    SetLastError(0xdeadbeef);
+    ret = lstrlenA(str);
+    error = GetLastError();
+    expect(len, ret);
+    expect(0xdeadbeef, error);
+}
+
+START_TEST(string)
+{
+    test_strlen();
+}
-- 
1.7.0.1


More information about the wine-patches mailing list