[stupid-crypto] push by ben@links.org - Add undeflow checking. on 2010-04-02 17:16 GMT

0 views
Skip to first unread message

stupid...@googlecode.com

unread,
Apr 2, 2010, 1:17:26 PM4/2/10
to stupi...@googlegroups.com
Revision: c1c99e69c0
Author: Ben Laurie <b...@links.org>
Date: Fri Apr 2 10:16:20 2010
Log: Add undeflow checking.
http://code.google.com/p/stupid-crypto/source/detail?r=c1c99e69c0

Added:
/test/underflow32.stupid
Modified:
/src/Stupid/C.pm

=======================================
--- /dev/null
+++ /test/underflow32.stupid Fri Apr 2 10:16:20 2010
@@ -0,0 +1,10 @@
+"EXPECT-RUN-FAIL:1 minus32 2 underflows
+";
+
+function() test() {
+ uint32 a = 1;
+ uint32 b = 2;
+ uint32 c = 0;
+
+ c = a minus32 b;
+}
=======================================
--- /src/Stupid/C.pm Fri Apr 2 07:49:18 2010
+++ /src/Stupid/C.pm Fri Apr 2 10:16:20 2010
@@ -48,6 +48,14 @@
stupid_fatal("%u plus32 %u overflows", a, b);
return t;
}
+
+uint32 minus32(const uint32 a, const uint32 b) {
+ uint32 t = a - b;
+ if(t > a)
+ stupid_fatal("%u minus32 %u underflows", a, b);
+ return t;
+}
+
EOC

$self->{tree}->emitCode();
@@ -725,9 +733,9 @@
sub Stupid::Minus32::emitCode {
my $self = shift;

- print '(';
+ print 'minus32(';
$self->{left}->emitCode();
- print ' - ';
+ print ', ';
$self->{right}->emitCode();
print ')';
}

Reply all
Reply to author
Forward
0 new messages