]> sourceware.org Git - systemtap.git/commitdiff
PR15782 cont'd: PR_Read_Complete should initialize vars more
authorFrank Ch. Eigler <fche@redhat.com>
Thu, 25 Jul 2013 20:01:31 +0000 (16:01 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Thu, 25 Jul 2013 20:01:31 +0000 (16:01 -0400)
Use a clearer looping/accumulation structure.

nsscommon.cxx

index 6fa3f983c44a312915f7dffddcbb5a27d9b89df5..ebc13e0986e8f9f282a1a4604e99f96e021faef7 100644 (file)
@@ -1349,9 +1349,9 @@ PRInt32 PR_Read_Complete (PRFileDesc *fd, void *buf, PRInt32 requestedBytes)
   // Read until EOF or until the expected number of bytes has been read.
   // PR_Read wants (void*), but we need (char *) to do address arithmetic.
   char *buffer = (char *)buf;
-  PRInt32 totalBytes;
-  PRInt32 bytesRead;
-  for (totalBytes = 0; totalBytes < requestedBytes; totalBytes += bytesRead)
+  PRInt32 totalBytes = 0;
+  PRInt32 bytesRead = 0;
+  while (1)
     {
       // Now read the data.
       bytesRead = PR_Read (fd, (void *)(buffer + totalBytes), requestedBytes - totalBytes);
@@ -1359,6 +1359,9 @@ PRInt32 PR_Read_Complete (PRFileDesc *fd, void *buf, PRInt32 requestedBytes)
        break;  // EOF
       if (bytesRead < 0)
        return bytesRead; // Error
+      totalBytes += bytesRead;
+      if (totalBytes == requestedBytes)
+        break;
     }
 
   // Return the number of bytes we managed to read.
This page took 0.028239 seconds and 5 git commands to generate.