Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
Add int multiplication overflow check
Browse files Browse the repository at this point in the history
  • Loading branch information
int3l authored and asottile committed Sep 19, 2021
1 parent ad7243a commit 72a4df9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
9 changes: 3 additions & 6 deletions make.py
Expand Up @@ -8,13 +8,10 @@

def output_on_failure(cmd, cwd):
print(f'$ cd {cwd} && {cmd}')
ret = subprocess.run(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd,
subprocess.run(
cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
check=True,
)
if ret.returncode:
raise AssertionError('Command {!r} returned {}!\nOutput:\n{}'.format(
cmd, ret.returncode, ret.stdout,
))


def run_test(bin_path, test):
Expand Down
9 changes: 3 additions & 6 deletions make0x.py
Expand Up @@ -8,13 +8,10 @@

def output_on_failure(cmd, cwd):
print(f'$ cd {cwd} && {cmd}')
ret = subprocess.run(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd,
subprocess.run(
cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
check=True,
)
if ret.returncode:
raise AssertionError('Command {!r} returned {}!\nOutput:\n{}'.format(
cmd, ret.returncode, ret.stdout,
))


def run_test(bin_path, test):
Expand Down
7 changes: 5 additions & 2 deletions python-0.9.1/src/intobject.c
Expand Up @@ -188,14 +188,17 @@ int_mul(v, w)
intobject *v;
register object *w;
{
register long a, b;
register long a, b, x;
if (!is_intobject(w)) {
err_badarg();
return NULL;
}
a = v->ob_ival;
b = ((intobject *)w) -> ob_ival;
return newintobject(a * b);
x = a * b;
if ( a != 0 && x / a != b)
return err_ovf();
return newintobject(x);
}

static object *
Expand Down

0 comments on commit 72a4df9

Please sign in to comment.