2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-31 06:16:03 +00:00

parser: fix i386 breakage on min() argument mismatches

Trunk commit 2456 broke the builds on i386 with the following compiler
error:

  g++ -g -O2 -pipe -Wall -Wsign-compare -Wmissing-field-initializers -Wformat-security -Wunused-parameter -std=gnu++0x -D_GNU_SOURCE -DPACKAGE=\"apparmor-parser\" -DLOCALEDIR=\"/usr/share/locale\" -DSUBDOMAIN_CONFDIR=\"/etc/apparmor\" -I../libraries/libapparmor//include -c -o lib.o lib.c
  lib.c: In function 'int strn_escseq(const char**, const char*, size_t)':
  lib.c:236:47: error: no matching function for call to 'min(long unsigned int, size_t&)'
     tmp = strntol(*pos, &end, 8, 255, min(3ul, n));
                                                ^

This is due to size_t differing in size on i386 and amd64. The
following patch addresses the issue by casting the constant values
to size_t (and removing the ul suffix since the constant values are
getting cast anyway), satisfying C++'s types (and the patch removes
the unnecessary min macro).

Signed-off-by: Steve Beattie <steve@nxnw.org>
Acked-by: John Johansen <john.johansen@canonical.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
This commit is contained in:
Steve Beattie
2014-04-17 09:20:40 -07:00
parent c9ed990016
commit e4cc8d1396
2 changed files with 3 additions and 8 deletions

View File

@@ -233,7 +233,7 @@ int strn_escseq(const char **pos, const char *chrs, size_t n)
return -1;
if (isodigit(**pos)) {
tmp = strntol(*pos, &end, 8, 255, min(3ul, n));
tmp = strntol(*pos, &end, 8, 255, min((size_t) 3, n));
if (tmp == 0 && end == *pos) {
/* this should never happen because of isodigit test */
return -1;
@@ -249,7 +249,7 @@ int strn_escseq(const char **pos, const char *chrs, size_t n)
case '"':
return '"';
case 'd':
tmp = strntol(*pos, &end, 10, 255, min(3ul, n));
tmp = strntol(*pos, &end, 10, 255, min((size_t) 3, n));
if (tmp == 0 && end == *pos) {
/* \d no valid encoding */
return -1;
@@ -257,7 +257,7 @@ int strn_escseq(const char **pos, const char *chrs, size_t n)
*pos = end;
return tmp;
case 'x':
tmp = strntol(*pos, &end, 16, 255, min(2ul, n));
tmp = strntol(*pos, &end, 16, 255, min((size_t) 2, n));
if (tmp == 0 && end == *pos) {
/* \x no valid encoding */
return -1;