[PATCH] handle potential error condition by open.

Marcus Meissner marcus at jet.franken.de
Mon Apr 9 10:58:29 CDT 2007


spotted by coverity.

Its is barely a bug, since the open succeeded
right before.

Ciao, Marcus
---
 dlls/msvcrt/tests/file.c |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index d7d7676..0284837 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -570,17 +570,19 @@ static void test_file_write_read( void )
 
   /* Test reading only \n or \r */
   tempfd = _open(tempf,_O_RDONLY|_O_TEXT); /* open in TEXT mode */
-  _lseek(tempfd, -1, FILE_END);
-  ret = _read(tempfd,btext,LLEN);
-  ok(ret == 1, "_read expected 1 got bad length: %d\n", ret);
-  _lseek(tempfd, -2, FILE_END);
-  ret = _read(tempfd,btext,LLEN);
-  ok(ret == 1 && *btext == '\n', "_read expected '\\n' got bad length: %d\n", ret);
-  _lseek(tempfd, -3, FILE_END);
-  ret = _read(tempfd,btext,2);
-  ok(ret == 1 && *btext == 'e', "_read expected 'e' got \"%.*s\" bad length: %d\n", ret, btext, ret);
-  ok(tell(tempfd) == 42, "bad position %lu expecting 42\n", tell(tempfd));
-  _close(tempfd);
+  if (tempfd != -1) {
+    _lseek(tempfd, -1, FILE_END);
+    ret = _read(tempfd,btext,LLEN);
+    ok(ret == 1, "_read expected 1 got bad length: %d\n", ret);
+    _lseek(tempfd, -2, FILE_END);
+    ret = _read(tempfd,btext,LLEN);
+    ok(ret == 1 && *btext == '\n', "_read expected '\\n' got bad length: %d\n", ret);
+    _lseek(tempfd, -3, FILE_END);
+    ret = _read(tempfd,btext,2);
+    ok(ret == 1 && *btext == 'e', "_read expected 'e' got \"%.*s\" bad length: %d\n", ret, btext, ret);
+    ok(tell(tempfd) == 42, "bad position %lu expecting 42\n", tell(tempfd));
+    _close(tempfd);
+  }
 
   ret = unlink(tempf);
   ok( ret == 0 ,"Can't unlink '%s': %d\n", tempf, errno);
-- 
1.4.3.4



More information about the wine-patches mailing list