Skip to content

Commit edb36fc

Browse files
soegaardmflatt
authored andcommitted
Repair for Issue #330
1 parent 6754ed4 commit edb36fc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

gui-lib/mred/private/wx/cocoa/key-translate.rkt

+5-4
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@
426426

427427
;; The strings used to store output from UCKeyTranslate is only allocated once:
428428
(define max-string-length 255)
429-
(define output-chars (malloc _UniChar max-string-length))
429+
(define output-chars (malloc _UniChar (add1 max-string-length))) ; leave room for a terminator
430430

431431
;; Dead key state
432432
; A pointer to an unsigned 32-bit value, initialized to zero.
@@ -490,10 +490,11 @@
490490
max-string-length
491491
actual-string-length
492492
output-chars)
493-
; get the number of characters returned, and convert to string
493+
;; get the number of characters returned, and convert to string;
494+
;; the characters are UTF-16
494495
(define n (max 0 (min max-string-length (unbox actual-string-length))))
495-
(list->string (for/list ([i (in-range n)])
496-
(integer->char (ptr-ref output-chars _UniChar i)))))
496+
(ptr-set! output-chars _UniChar n 0) ; ensure nul terminator
497+
(cast output-chars _pointer _string/utf-16))
497498

498499
;;;
499500
;;; Conversions back and forth between characters and key codes.

0 commit comments

Comments
 (0)