Skip to content

Fix -Wpointer-sign warnings (char * vs u_char * mismatches) #361

Description

@thegushi

Clang on FreeBSD surfaces 156 instances of -Wpointer-sign across 9 files, all variations of implicit conversion between char * and u_char * / unsigned char *.

Affected files

  • libopendkim/dkim.c (many instances — string literals assigned to const u_char *)
  • libopendkim/dkim-keys.c
  • libopendkim/dkim-mailparse.c
  • libopendkim/dkim-report.c
  • libopendkim/dkim-test.c
  • opendkim/opendkim.c
  • opendkim/opendkim-db.c
  • opendkim/opendkim-dns.c
  • opendkim/opendkim-testmsg.c

Pattern

The codebase uses u_char * for DKIM/DNS data (which is correct — it's binary content) but passes these buffers to standard C string functions that expect char *, and vice versa. Clang treats char and unsigned char as distinct types and warns on implicit pointer conversions between them; gcc does not warn by default.

Notes

  • gcc with -Wformat-truncation and -Wincompatible-pointer-types is being addressed in Fix compiler warnings (-Wincompatible-pointer-types, -Wformat-truncation) #360. This is a separate, clang-specific (but also standards-correct) issue.
  • Fixes will likely be (char *) or (u_char *) casts at call sites, or changing buffer declarations to match the dominant usage in context. The right answer varies by site.
  • dkim.c:219-235 is likely a block of string literal initializers; those may want (const u_char *) casts or the receiving type changed.
  • This does not affect correctness on any current platform — char and unsigned char have the same representation and alignment — but it is noise that makes it harder to spot real warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions