fix: script run e - if called with param but no value, use default value for width.

fix: if no models found, return lua error.
textual changes.
This commit is contained in:
iceman1001 2018-02-03 22:17:07 +01:00
commit 8a49cb84a2
3 changed files with 23 additions and 17 deletions

View file

@ -453,21 +453,26 @@ static int l_sha1(lua_State *L) {
static int l_reveng_models(lua_State *L){
// This array needs to be adjusted if RevEng adds more crc-models.
char *models[100];
int count = 0;
int in_width = luaL_checkinteger(L, 1);
uint8_t in_width = luaL_checkunsigned(L, 1);
if ( in_width > 89 ) return returnToLuaWithError(L,"Width cannot exceed 89, got %d", in_width);
// This array needs to be adjusted if RevEng adds more crc-models.
uint8_t width[100];
width[0] = (uint8_t)in_width;
uint8_t width[102];
// This array needs to be adjusted if RevEng adds more crc-models.
char *models[102];
width[0] = in_width;
int ans = GetModels(models, &count, width);
if (!ans) return 0;
lua_newtable(L);
if (!ans) {
for (int i =0; i<102; i++) {
free(models[i]);
}
return returnToLuaWithError(L, "Didn't find any models");
}
lua_newtable(L);
for (int i = 0; i < count; i++){
lua_pushstring(L, (const char*)models[i]);
lua_rawseti(L,-2,i+1);