aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Zborovskii <vadim_z@triniti.ru>2012-07-13 20:58:38 +0400
committerSteve Bennett <steveb@workware.net.au>2012-09-24 19:18:02 +1000
commit45e938f72dad52f897d6e89fb41470829e596238 (patch)
treedd74d5ac83b729d859abb8570841618887ab6b93
parent76a9f361d5db21434ee6cdeb44d945f3ad21d2bf (diff)
downloadjimtcl-45e938f72dad52f897d6e89fb41470829e596238.zip
jimtcl-45e938f72dad52f897d6e89fb41470829e596238.tar.gz
jimtcl-45e938f72dad52f897d6e89fb41470829e596238.tar.bz2
Fix binary scan for too-few bytes.
According to the Tcl manual, in this case "binary scan returns immediately with the number of variables that were set". (Tests added by Steve Bennett) Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--binary.tcl4
-rw-r--r--tests/binary-scan.test15
2 files changed, 17 insertions, 2 deletions
diff --git a/binary.tcl b/binary.tcl
index 5e9ae3f..cc9c9ea 100644
--- a/binary.tcl
+++ b/binary.tcl
@@ -125,7 +125,7 @@ proc "binary scan" {value formatString {args varName}} {
set n 1
}
if {$n > $rembytes} {
- continue
+ break
}
set var [binary.nextarg varName]
@@ -148,7 +148,7 @@ proc "binary scan" {value formatString {args varName}} {
}
}
if {$n * $size > $rembytes * 8} {
- continue
+ break
}
if {$type ne "int"} {
diff --git a/tests/binary-scan.test b/tests/binary-scan.test
index c758f05..ec6c95c 100644
--- a/tests/binary-scan.test
+++ b/tests/binary-scan.test
@@ -74,6 +74,13 @@ test binary-20.9 {Tcl_BinaryObjCmd: scan} -setup {
list [binary scan abc a arg1(a)] $arg1(a)
} -result {1 a}
+# As soon as a conversion runs out of bytes, scan should stop
+test binary-20.10 {Tcl_BinaryObjCmd: scan, too few bytes} -setup {
+ unset -nocomplain arg1 arg2
+} -body {
+ list [binary scan abc a5a2 arg1 arg2] [info exists arg1] [info exists arg2]
+} -result {0 0 0}
+
test binary-21.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc A
} -result {not enough arguments for all format specifiers}
@@ -185,6 +192,14 @@ test binary-22.11 {Tcl_BinaryObjCmd: scan} -setup {
list [binary scan \x07\x87\x05 b5b* arg1 arg2] $arg1 $arg2
} -result {2 11100 1110000110100000}
+# As soon as a conversion runs out of bytes, scan should stop
+test binary-20.12 {Tcl_BinaryObjCmd: scan, too few bytes} {
+ unset -nocomplain arg1 arg2
+ set arg1 foo
+ set arg2 bar
+ list [binary scan \x52 b14b8 arg1 arg2] $arg1 $arg2
+} {0 foo bar}
+
test binary-23.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc B
} -result {not enough arguments for all format specifiers}