Fix crashing when accessing out of global arrays
This commit is contained in:
1 parent
9ea9bea096
commit
e362f3cab9
3 files changed
+4
-5
No files matched your search
+2
-2
@@ -51,7 +51,7 @@ enum device device_from_string(const char * device) {
|
||||
|
||||
const char * device_to_string(enum device device) {
|
||||
|
||||
if ( device > sizeof(devices)/sizeof(devices[0]) )
|
||||
if ( device >= sizeof(devices)/sizeof(devices[0]) )
|
||||
return NULL;
|
||||
|
||||
return devices[device];
|
||||
@@ -68,7 +68,7 @@ static const char * long_devices[] = {
|
||||
|
||||
const char * device_to_long_string(enum device device) {
|
||||
|
||||
if ( device > sizeof(long_devices)/sizeof(long_devices[0]) )
|
||||
if ( device >= sizeof(long_devices)/sizeof(long_devices[0]) )
|
||||
return NULL;
|
||||
|
||||
return long_devices[device];
|
||||
|
||||
+1
-1
@@ -540,7 +540,7 @@ enum image_type image_type_from_string(const char * type) {
|
||||
|
||||
const char * image_type_to_string(enum image_type type) {
|
||||
|
||||
if ( type > sizeof(image_types)/sizeof(image_types[0]) )
|
||||
if ( type >= sizeof(image_types)/sizeof(image_types[0]) )
|
||||
return NULL;
|
||||
|
||||
return image_types[type];
|
||||
|
||||
+1
-2
@@ -300,7 +300,7 @@ static const char * image_tmp[] = {
|
||||
|
||||
static const char * image_tmp_name(enum image_type type) {
|
||||
|
||||
if ( type > sizeof(image_tmp)/sizeof(image_tmp[0]) )
|
||||
if ( type >= sizeof(image_tmp)/sizeof(image_tmp[0]) )
|
||||
return NULL;
|
||||
|
||||
if ( ! image_tmp[type] || ! image_tmp[type][0] )
|
||||
@@ -1288,7 +1288,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user