• Alex Brainman's avatar
    os: make readConsole handle its input and output correctly · 1af769da
    Alex Brainman authored
    This CL introduces first test for readConsole. And new test
    discovered couple of problems with readConsole.
    
    Console characters consist of multiple bytes each, but byte blocks
    returned by syscall.ReadFile have no character boundaries. Some
    multi-byte characters might start at the end of one block, and end
    at the start of next block. readConsole feeds these blocks to
    syscall.MultiByteToWideChar to convert them into utf16, but if some
    multi-byte characters have no ending or starting bytes, the
    syscall.MultiByteToWideChar might get confused. Current version of
    syscall.MultiByteToWideChar call will make
    syscall.MultiByteToWideChar ignore all these not complete
    multi-byte characters.
    
    The CL solves this issue by changing processing from "randomly
    sized block of bytes at a time" to "one multi-byte character at a
    time". New readConsole code calls syscall.ReadFile to get 1 byte
    first. Then it feeds this byte to syscall.MultiByteToWideChar.
    The new syscall.MultiByteToWideChar call uses MB_ERR_INVALID_CHARS
    flag to make syscall.MultiByteToWideChar return error if input is
    not complete character. If syscall.MultiByteToWideChar returns
    correspondent error, we read another byte and pass 2 byte buffer
    into syscall.MultiByteToWideChar, and so on until success.
    
    Old readConsole code would also sometimes return no data if user
    buffer was smaller then uint16 size, which would confuse callers
    that supply 1 byte buffer. This CL fixes that problem too.
    
    Fixes #17097
    
    Change-Id: I88136cdf6a7bf3aed5fbb9ad2c759b6c0304ce30
    Reviewed-on: https://go-review.googlesource.com/29493
    Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
    1af769da
Name
Last commit
Last update
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
context Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal Loading commit data...
io Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
plugin Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
vendor/golang_org/x Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
bootstrap.bash Loading commit data...
buildall.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
cmp.bash Loading commit data...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
naclmake.bash Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...