libpkgconf: pkg: warn when encountering trailing whitespace

feature/tap-sh
William Pitcock 2017-01-26 13:32:07 -06:00
parent da34d940ea
commit 2fa4fd09d0
1 changed files with 18 additions and 0 deletions

View File

@ -238,6 +238,7 @@ pkgconf_pkg_new_from_file(const pkgconf_client_t *client, const char *filename,
pkgconf_pkg_t *pkg; pkgconf_pkg_t *pkg;
char readbuf[PKGCONF_BUFSIZE]; char readbuf[PKGCONF_BUFSIZE];
char *idptr; char *idptr;
size_t lineno = 0;
pkg = calloc(sizeof(pkgconf_pkg_t), 1); pkg = calloc(sizeof(pkgconf_pkg_t), 1);
pkg->filename = strdup(filename); pkg->filename = strdup(filename);
@ -257,6 +258,9 @@ pkgconf_pkg_new_from_file(const pkgconf_client_t *client, const char *filename,
while (pkgconf_fgetline(readbuf, PKGCONF_BUFSIZE, f) != NULL) while (pkgconf_fgetline(readbuf, PKGCONF_BUFSIZE, f) != NULL)
{ {
char op, *p, *key, *value; char op, *p, *key, *value;
bool warned_key_whitespace = false, warned_value_whitespace = false;
lineno++;
p = readbuf; p = readbuf;
while (*p && (isalpha((unsigned int)*p) || isdigit((unsigned int)*p) || *p == '_' || *p == '.')) while (*p && (isalpha((unsigned int)*p) || isdigit((unsigned int)*p) || *p == '_' || *p == '.'))
@ -268,6 +272,13 @@ pkgconf_pkg_new_from_file(const pkgconf_client_t *client, const char *filename,
while (*p && isspace((unsigned int)*p)) while (*p && isspace((unsigned int)*p))
{ {
if (!warned_key_whitespace)
{
pkgconf_error(client, "%s:%zu: warning: whitespace encountered while parsing key section\n",
pkg->filename, lineno);
warned_key_whitespace = true;
}
/* set to null to avoid trailing spaces in key */ /* set to null to avoid trailing spaces in key */
*p = '\0'; *p = '\0';
p++; p++;
@ -284,6 +295,13 @@ pkgconf_pkg_new_from_file(const pkgconf_client_t *client, const char *filename,
p = value + (strlen(value) - 1); p = value + (strlen(value) - 1);
while (*p && isspace((unsigned int) *p) && p > value) while (*p && isspace((unsigned int) *p) && p > value)
{ {
if (!warned_value_whitespace && op == '=')
{
pkgconf_error(client, "%s:%zu: warning: trailing whitespace encountered while parsing value section\n",
pkg->filename, lineno);
warned_value_whitespace = true;
}
*p = '\0'; *p = '\0';
p--; p--;
} }