1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

Fix segfault when no actions are found.

This commit is contained in:
King_DuckZ 2016-04-30 19:41:00 +02:00
parent 76a289df62
commit 265337607e
2 changed files with 7 additions and 0 deletions

View file

@ -24,6 +24,7 @@
#include <iso646.h> #include <iso646.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h>
typedef struct ActionListStruct { typedef struct ActionListStruct {
char** list; char** list;
@ -39,10 +40,14 @@ static int strcmp_wrapper ( const void* parA, const void* parB );
void find_actions (char*** parOut, size_t* parCount) { void find_actions (char*** parOut, size_t* parCount) {
ActionList list; ActionList list;
assert(parOut);
assert(parCount);
list.count = 0; list.count = 0;
foreach_dir(&increase_actionlist, &list); foreach_dir(&increase_actionlist, &list);
if (0 == list.count) { if (0 == list.count) {
*parOut = NULL; *parOut = NULL;
*parCount = 0;
return; return;
} }

View file

@ -29,6 +29,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <getopt.h> #include <getopt.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
/* This program can be run either with the name of a subcommand as its first /* This program can be run either with the name of a subcommand as its first
* parameter (eg: dindexer locate), plus some optional parameters that are just * parameter (eg: dindexer locate), plus some optional parameters that are just
@ -87,6 +88,7 @@ int main (int parArgc, char* parArgv[]) {
specified_action = parArgv[1]; specified_action = parArgv[1];
else else
specified_action = ""; specified_action = "";
assert((actions and actions_count) or (not actions and not actions_count));
selected_action = foreach_avail_action(&same_action, actions, actions_count, specified_action); selected_action = foreach_avail_action(&same_action, actions, actions_count, specified_action);
if (actions_count == selected_action) { if (actions_count == selected_action) {