unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] fport_write: Fix test of remaining bytes.
@ 2015-03-28 20:59 Doug Evans
  2015-03-31 19:31 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Doug Evans @ 2015-03-28 20:59 UTC (permalink / raw)
  To: guile-devel

Hi.

This seems obvious, but I could be missing something.

2015-03-28  Doug Evans  <xdje42@gmail.com>

	* libguile/fports.c (fport_write): Fix test of remaining bytes.

diff --git a/libguile/fports.c b/libguile/fports.c
index 8395f0e..ce1bf54 100644
--- a/libguile/fports.c
+++ b/libguile/fports.c
@@ -869,7 +869,7 @@ fport_write (SCM port, const void *data, size_t size)
 	  const void *ptr = ((const char *) data) + space;
 	  size_t remaining = size - space;
 
-	  if (size >= pt->write_buf_size)
+	  if (remaining >= pt->write_buf_size)
 	    {
 	      if (full_write (SCM_FPORT_FDES (port), ptr, remaining)
 		  < remaining)



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fport_write: Fix test of remaining bytes.
  2015-03-28 20:59 [PATCH] fport_write: Fix test of remaining bytes Doug Evans
@ 2015-03-31 19:31 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2015-03-31 19:31 UTC (permalink / raw)
  To: Doug Evans; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]

Doug Evans <xdje42@gmail.com> skribis:

> diff --git a/libguile/fports.c b/libguile/fports.c
> index 8395f0e..ce1bf54 100644
> --- a/libguile/fports.c
> +++ b/libguile/fports.c
> @@ -869,7 +869,7 @@ fport_write (SCM port, const void *data, size_t size)
>  	  const void *ptr = ((const char *) data) + space;
>  	  size_t remaining = size - space;
>  
> -	  if (size >= pt->write_buf_size)
> +	  if (remaining >= pt->write_buf_size)
>  	    {
>  	      if (full_write (SCM_FPORT_FDES (port), ptr, remaining)
>  		  < remaining)

I spent a bit of time looking at this code.  The change makes sense, so
I have committed it.  AFAICS, it has no observable effect though,
because (size >= remaining) is always true here.

The attached program reproduces a case where we would take one branch
before the patch, and the other after the patch.

Thanks,
Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: the example --]
[-- Type: text/x-scheme, Size: 958 bytes --]

(use-modules (rnrs io ports)
             (rnrs bytevectors))

(define %seed
  (seed->random-state (logxor (getpid) (car (gettimeofday)))))

(define (random-bytevector n)
  "Return a random bytevector of N bytes."
  (let ((bv (make-bytevector n)))
    (let loop ((i 0))
      (if (< i n)
          (begin
            (bytevector-u8-set! bv i (random 256 %seed))
            (loop (1+ i)))
          bv))))

(let* ((file ",t")
       (port (open-file file "wb"))
       (size 777)
       (bv1  (random-bytevector (- size 1)))
       (bv2  (random-bytevector size)))
  (setvbuf port _IOFBF size)
  (put-bytevector port bv1)
  (put-bytevector port bv2)
  (close-port port)

  (call-with-input-file file
    (lambda (port)
      (let ((one (get-bytevector-n port (bytevector-length bv1)))
            (two (get-bytevector-n port (bytevector-length bv2))))
        (pk (and (pk 'one (bytevector=? one bv1))
                 (pk 'two (bytevector=? two bv2))))))))

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-31 19:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-28 20:59 [PATCH] fport_write: Fix test of remaining bytes Doug Evans
2015-03-31 19:31 ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).