Skip to content

Commit 0842c3b

Browse files
committed
Fix dumb bug in program argument handling (assert nonnegative on signed long rather than unsigned!)
1 parent c8c8f8d commit 0842c3b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

python/conway_game_of_life/life.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,19 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
135135
{
136136
#ifdef USER_PARAMS
137137
assert(argc > 4);
138-
size_t w = atol(argv[1]);
139-
size_t h = atol(argv[2]);
140-
Automata::index_t x = atol(argv[3]);
141-
Automata::index_t y = atol(argv[4]);
138+
long warg = atol(argv[1]);
139+
long harg = atol(argv[2]);
140+
long xarg = atol(argv[3]);
141+
long yarg = atol(argv[4]);
142+
assert(warg > 0);
143+
assert(harg > 0);
144+
assert(xarg >= 0);
145+
assert(yarg >= 0);
146+
size_t w = (size_t)warg;
147+
size_t h = (size_t)harg;
148+
Automata::index_t x = (Automata::index_t)xarg;
149+
Automata::index_t y = (Automata::index_t)yarg;
142150
fmt::print("Using parameters from command line: game size ({} x {}), glider start position ({}, {}).\n", w, h, x, y);
143-
assert(w > 0);
144-
assert(h > 0);
145-
assert(x >= 0);
146-
assert(y >= 0);
147151
#else
148152
const size_t w = 40;
149153
const size_t h = 20;

0 commit comments

Comments
 (0)