2024-10-18 05:40 BST

View Revisions: Issue #2870

Summary 0002870: 0.9.2 tests fail to build on 32-bit system
Revision 2024-05-25 12:14 by Vincent Sanders
Description When attempting to compile libcss tests for a i686-linux system, I get the following error:

```
In file included from test/css21.c:11:
test/dump.h: In function ‘dump_rule_media’:
test/dump.h:134:45: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]
  134 | ptr += sprintf(ptr, "| @media %s%03lx",
      | ~~~~^
      | |
      | long unsigned int
      | %03llx
  135 | s->media->negate_type ? "not " : "",
  136 | s->media->type);
      | ~~~~~~~~~~~~~~
      | |
      | uint64_t {aka long long unsigned int}
In file included from test/parse2-auto.c:12:
test/dump.h: In function ‘dump_rule_media’:
test/dump.h:134:45: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]
  134 | ptr += sprintf(ptr, "| @media %s%03lx",
      | ~~~~^
      | |
      | long unsigned int
      | %03llx
  135 | s->media->negate_type ? "not " : "",
  136 | s->media->type);
      | ~~~~~~~~~~~~~~
      | |
      | uint64_t {aka long long unsigned int}
 COMPILE: test/select.c
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_lex
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_parse
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_csdetect
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_number
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_lex-auto
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_parse-auto
cc1: all warnings being treated as errors
```

The format specifier `%lx` does not match the `uint64_t` declaration on 32-bit systems, where `long int` is not 64 bits wide.

Anyhow, the following patch appears to fix the issue:

```
--- a/test/dump.h
+++ b/test/dump.h
@@ -131,7 +131,7 @@ void dump_rule_media(css_rule_media *s, char **buf, size_t *buflen)
        char *ptr = *buf;
        css_rule *rule;
 
- ptr += sprintf(ptr, "| @media %s%03lx",
+ ptr += sprintf(ptr, "| @media %s%03" PRIx64,
                        s->media->negate_type ? "not " : "",
                        s->media->type);
```

since the <inttypes.h> header is already in use.
Revision 2024-03-09 04:21 by Richard Bauer
Description When attempting to compile libcss tests for a i686-linux system, I get the following error:

```
In file included from test/css21.c:11:
test/dump.h: In function ‘dump_rule_media’:
test/dump.h:134:45: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]
  134 | ptr += sprintf(ptr, "| @media %s%03lx",
      | ~~~~^
      | |
      | long unsigned int
      | %03llx
  135 | s->media->negate_type ? "not " : "",
  136 | s->media->type);
      | ~~~~~~~~~~~~~~
      | |
      | uint64_t {aka long long unsigned int}
In file included from test/parse2-auto.c:12:
test/dump.h: In function ‘dump_rule_media’:
test/dump.h:134:45: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]
  134 | ptr += sprintf(ptr, "| @media %s%03lx",
      | ~~~~^
      | |
      | long unsigned int
      | %03llx
  135 | s->media->negate_type ? "not " : "",
  136 | s->media->type);
      | ~~~~~~~~~~~~~~
      | |
      | uint64_t {aka long long unsigned int}
 COMPILE: test/select.c
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_lex
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_parse
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_csdetect
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_number
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_lex-auto
    LINK: build-i686-unknown-linux-gnu-i686-unknown-linux-gnu-release-lib-shared/test_parse-auto
cc1: all warnings being treated as errors
```

The format specifier `%lx` does not match the `uint64_t` declaration on 32-bit systems, where `long int` is not 64 bits wide.

Anyhow, the following patch appears to fix the issue:

```
--- a/test/dump.h
+++ b/test/dump.h
@@ -131,7 +131,7 @@ void dump_rule_media(css_rule_media *s, char **buf, size_t *buflen)
        char *ptr = *buf;
        css_rule *rule;
 
- ptr += sprintf(ptr, "| @media %s%03lx",
+ ptr += sprintf(ptr, "| @media %s%03" PRIx64,
                        s->media->negate_type ? "not " : "",
                        s->media->type);
```

since the <inttypes.h> header is already in use.