Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore fcontext lines containing only spaces #283

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/parse_fc.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -135,8 +136,7 @@ struct fc_entry *parse_fc_line(char *line)
} else {
out->context->range = NULL;
}
} else if (strcmp("<<none>>\n", pos) == 0
|| strcmp("<<none>>\r\n", pos) == 0) {
} else if (strcmp("<<none>>", pos) == 0) {
out->context = NULL;
} else {
out->context = parse_context(pos);
Expand Down Expand Up @@ -229,6 +229,12 @@ bool check_for_fc_macro(const char *line, const struct string_list *custom_fc_ma
return false;
}

static void rtrim(char *line, size_t len)
{
while (len > 0 && isspace((unsigned char)line[len - 1]))
line[--len] = '\0';
}

struct policy_node *parse_fc_file(const char *filename, const struct string_list *custom_fc_macros)
{
FILE *fd = fopen(filename, "re");
Expand All @@ -253,6 +259,13 @@ struct policy_node *parse_fc_file(const char *filename, const struct string_list
if (len_read <= 1 || line[0] == '#') {
continue;
}

// Drop trailing white spaces
rtrim(line, (size_t)len_read);

if (*line == '\0')
continue;

// Skip over m4 constructs
if (strncmp(line, "ifdef", 5) == 0 ||
strncmp(line, "ifndef", 6) == 0 ||
Expand All @@ -262,8 +275,6 @@ struct policy_node *parse_fc_file(const char *filename, const struct string_list

continue;
}
// TODO: Right now whitespace parses as an error
// We may want to detect it and report a lower severity issue

if (check_for_fc_macro(line, custom_fc_macros)) {
continue;
Expand Down