Commit 4802b4be authored by Peter Barker's avatar Peter Barker Committed by Rusty Russell

ccanlint - avoid e.g. GPL vs LGPL mismatch in license checking

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent c2fbfe52
......@@ -11,6 +11,40 @@
#include <err.h>
#include <ccan/str/str.h>
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 <flavour> 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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment