From 4802b4bece8edf21cc64abdc25158d7437a9cfc6 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 25 Feb 2015 14:34:14 +1100 Subject: [PATCH] ccanlint - avoid e.g. GPL vs LGPL mismatch in license checking Signed-off-by: Rusty Russell --- tools/ccanlint/tests/license_comment.c | 38 ++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tools/ccanlint/tests/license_comment.c b/tools/ccanlint/tests/license_comment.c index 9548d87c..88943e1c 100644 --- a/tools/ccanlint/tests/license_comment.c +++ b/tools/ccanlint/tests/license_comment.c @@ -11,6 +11,40 @@ #include #include +static char *xstrdup(const char *s) { + char * ret = strdup(s); + if (ret == NULL) { + perror("strdup"); + abort(); + } + return ret; +} + +/** + * line_has_license_flavour - returns true if line contains a license + * @line: line to look for license in + * @shortname: license to find + * @note ("LGPLv2.0","LGPL") returns true + * @note ("LGPLv2.0","GPL") returns false + */ +static bool line_has_license_flavour(const char *line, const char *flavour) { + char *strtok_line, *strtok_tmp, *token; + bool ret = false; + const size_t flavour_len = strlen(flavour); + + strtok_line = strtok_tmp = xstrdup(line); + while((token = strtok(strtok_tmp, " \t-:")) != NULL) { + if (!strncmp(token, flavour, flavour_len)) { + ret = true; + break; + } + strtok_tmp = NULL; + } + free(strtok_line); + + return ret; +} + static void check_license_comment(struct manifest *m, unsigned int *timeleft, struct score *score) { @@ -38,8 +72,8 @@ static void check_license_comment(struct manifest *m, break; if (strstr(lines[i], "LICENSE")) found_license = true; - if (strstr(lines[i], - licenses[m->license].shortname)) + if (line_has_license_flavour(lines[i], + licenses[m->license].shortname)) found_flavor = true; } if ((!found_license || !found_flavor) -- 2.39.2