Skip to content

Commit

Permalink
Validation for classification to ensure 2 slashes (#4)
Browse files Browse the repository at this point in the history
* Validation for classification to ensure 2 slashes

Signed-off-by: John Andersen <[email protected]>

* Update telem_record_gen.c

Fixed code style issues
  • Loading branch information
pdxjohnny authored and rnesius committed Sep 2, 2016
1 parent 44e0d4d commit cb622a0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/probes/telem_record_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ static GOptionEntry options[] = {
{ NULL }
};

const unsigned int count_chars(const char *check, const char character)
{
unsigned int count = 0U;
if (check == NULL) {
return count;
}
for (; *check != '\0'; ++check) {
if (*check == character) {
++count;
}
}
return count;
}

static void free_glib_strings(void)
{
if (config_file) {
Expand Down Expand Up @@ -122,6 +136,12 @@ int validate_opts(void)
return ret;
}

if (count_chars(opt_class, '/') != 2) {
fprintf(stderr, "Error: Classification needs to be in "
"most/to/least specific format, 2 \'/\' required.\n");
return ret;
}

/* Severity */
if ((severity) < 1 || (severity > 4)) {
fprintf(stderr, "Error: Valid range for severity is 1-4\n");
Expand Down

0 comments on commit cb622a0

Please sign in to comment.