From b72f620aed4e75fcabf3952a2d877481d1a3a894 Mon Sep 17 00:00:00 2001 From: Martin Guy Date: Sat, 21 Jan 2012 20:00:34 +0100 Subject: [PATCH] Fix to previous commit: unsigned values never look negative! --- src/modules/adc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/adc.c b/src/modules/adc.c index 2b3e436f..f19abf31 100644 --- a/src/modules/adc.c +++ b/src/modules/adc.c @@ -28,14 +28,16 @@ static int adc_maxval( lua_State* L ) // Lua: realclock = setclock( id, freq, [timer_id] ) static int adc_setclock( lua_State* L ) { + s32 sfreq; // signed version for negative checking u32 freq; unsigned id, timer_id = 0; id = luaL_checkinteger( L, 1 ); MOD_CHECK_ID( adc, id ); - freq = luaL_checkinteger( L, 2 ); - if ( freq < 0 ) + sfreq = luaL_checkinteger( L, 2 ); + if ( sfreq < 0 ) return luaL_error( L, "frequency must be 0 or positive" ); + freq = ( u32 ) sfreq; if ( freq > 0 ) { timer_id = luaL_checkinteger( L, 3 );