Ticket #1254: stty-should-not-segfault.patch

File stty-should-not-segfault.patch, 850 bytes (added by Christian Kellermann, 6 years ago)
  • stty.scm

    old new  
    370370
    371371(define (stty . args)
    372372
    373   (let* ((port (if (and (pair? args) (port? (car args)))
     373  (and-let* ((port (if (and (pair? args) (port? (car args)))
    374374                   (car args)
    375375                   (current-input-port)))
    376376         (attr (get-terminal-attributes port))
     
    438438(define (with-stty setting thunk)
    439439  (let* ((port (current-input-port))
    440440         (orig-attrs (get-terminal-attributes port)))
     441    (if orig-attrs
    441442    (dynamic-wind
    442443        (lambda ()
    443444          (stty setting))
    444445        thunk
    445446        (lambda ()
    446447          (set-terminal-attributes! port TCSANOW orig-attrs)
    447           (free-term-attrs orig-attrs)))))
     448              (free-term-attrs orig-attrs)))
     449        (thunk))))
    448450
    449451)