Skip to content

Fix three feature-combination build failures (NO_STDIO / CUSTOM_MALLOC / SESSION_ID_TRACK) - #619

Closed
warter666 wants to merge 1 commit into
wolfSSL:masterfrom
warter666:fix/feature-combo-build
Closed

warter666 wants to merge 1 commit into
wolfSSL:masterfrom
warter666:fix/feature-combo-build

Conversation

@warter666

Copy link
Copy Markdown

A -Werror compile sweep over feature-macro combinations found three combinations that fail to build, all in code paths CI does not cover. Reproduced with gcc 11.4 (gcc -c -Werror -I. -DWOLFMQTT_NO_TLS ...) against master eafb9c1; all 19 NO_TLS combinations build clean after this PR.

1. WOLFMQTT_NO_STDIO — implicit declaration of malloc/free

mqtt_types.h defines WOLFMQTT_MALLOC/WOLFMQTT_FREE in terms of malloc()/free(), but <stdlib.h> was only included inside the #ifndef WOLFMQTT_NO_STDIO block. A NO_STDIO build therefore failed:

mqtt_types.h:317:63: error: implicit declaration of function 'free'
mqtt_types.h:314:37: error: implicit declaration of function 'malloc'

Fix: <stdlib.h>/<string.h> are needed by the default allocator and string helpers regardless of printf availability, so they are now included unconditionally; only <stdio.h> stays behind the WOLFMQTT_NO_STDIO guard.

2. WOLFMQTT_CUSTOM_MALLOC without user macros — confusing failure

Defining WOLFMQTT_CUSTOM_MALLOC without also defining WOLFMQTT_MALLOC/WOLFMQTT_FREE produced a misleading implicit-declaration error deep inside mqtt_client.c (implicit declaration of function 'WOLFMQTT_FREE'). The header now fails fast with a #error explaining what to define, mirroring the existing WOLFMQTT_CUSTOM_STRING pattern a few lines above.

3. -DWOLFMQTT_SESSION_ID_TRACK — macro redefinition under -Werror

mqtt_client.h redefines WOLFMQTT_SESSION_ID_TRACK without a guard, so a user passing -DWOLFMQTT_SESSION_ID_TRACK on the command line (for example to force session-id tracking while WOLFMQTT_MAX_QOS < 2 and session replay is disabled) hits a redefinition warning, fatal under -Werror. The internal define is now wrapped in #ifndef, and the MQTT_MAX_SESSION_CLIENT_ID validation block is keyed off the effective definition so both paths (command-line and internal) get the same constants.

Tested with the sweep matrix: baseline, V5, SN, V5+SN, MULTITHREAD, NONBLOCK, STATIC_MEMORY, V5+PROPERTY_CB, V5+DISCONNECT_CB, V5+SESSION_ID_TRACK, BROKER, BROKER+V5, BROKER+SN, BROKER+MULTITHREAD, V5+SN+MULTITHREAD+STATIC_MEMORY, NO_STDIO, NO_ERROR_STRINGS, V5+NO_STDIO, CUSTOM_MALLOC(with macros). (WOLFMQTT_USER_THREADING intentionally requires user-supplied wm_Sem and was excluded.)

A -Werror compile sweep over feature-macro combinations found three
combinations that fail to build, all in code paths that CI does not
cover:

1. WOLFMQTT_NO_STDIO: mqtt_types.h used malloc()/free() (for the
   default WOLFMQTT_MALLOC/WOLFMQTT_FREE) but only included <stdlib.h>
   inside the '#ifndef WOLFMQTT_NO_STDIO' block, so NO_STDIO builds
   failed with implicit-function-declaration. stdlib.h/string.h are
   now included unconditionally; only stdio.h stays behind the guard.

2. WOLFMQTT_CUSTOM_MALLOC: defining WOLFMQTT_CUSTOM_MALLOC without also
   defining WOLFMQTT_MALLOC/WOLFMQTT_FREE produced a confusing
   implicit-declaration error deep in mqtt_client.c. It now fails fast
   with a '#error' explaining what to define, mirroring the existing
   WOLFMQTT_CUSTOM_STRING pattern.

3. WOLFMQTT_SESSION_ID_TRACK: mqtt_client.h defined it unguarded, so
   passing -DWOLFMQTT_SESSION_ID_TRACK on the command line (e.g. to
   force tracking with WOLFMQTT_MAX_QOS<2 and session replay disabled)
   triggered a macro-redefinition warning under -Werror. The internal
   define is now guarded.

Repro: gcc -c -Werror -I. -DWOLFMQTT_NO_TLS [-DWOLFMQTT_V5 ...] src/*.c
All 19 NO_TLS combinations now build clean.
Copilot AI lite review requested due to automatic review settings September 17, 2026 10:51
@wolfSSL-Bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The include guard issue and requested compile-matrix coverage remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This pull request fixes feature-macro build failures involving standard-library includes, custom allocator validation, and session-ID tracking.

Changes:

  • Adjusts allocator and string header handling.
  • Validates incomplete custom allocator configuration.
  • Guards session-tracking definitions and validation.
File summaries
File Summary
wolfmqtt/mqtt_types.h Updates allocator validation and standard-library include handling.
wolfmqtt/mqtt_client.h Guards session-tracking configuration and client-ID validation.
Review details

Suppressed comments (2)

wolfmqtt/mqtt_types.h:320

  • The repository's automated build matrices currently cover WOLFMQTT_MAX_QOS but do not compile the NO_STDIO, CUSTOM_MALLOC, or pre-defined SESSION_ID_TRACK combinations (see .github/workflows/cmake-build.yml:21-32). Because these are compile-time regressions, please add a checked-in offline compile/smoke matrix for the combinations fixed here so a later header change cannot reintroduce the failures.
#elif !defined(WOLFMQTT_MALLOC) || !defined(WOLFMQTT_FREE)
    #error "WOLFMQTT_CUSTOM_MALLOC set: please define WOLFMQTT_MALLOC and WOLFMQTT_FREE"

wolfmqtt/mqtt_types.h:381

  • This include is now unconditional with respect to WOLFMQTT_CUSTOM_STRING. A custom-string port can define all of its X* wrappers (including XMEMCHR) specifically to avoid <string.h>; with WOLFMQTT_NO_STDIO, the previous header did not require this system header, but this change does. Keep the include guarded by !WOLFMQTT_CUSTOM_STRING (the default wrappers already include it at line 255) so custom string ports remain portable.
    #include <string.h>
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread wolfmqtt/mqtt_types.h
Comment on lines +380 to +381
#include <stdlib.h>
#include <string.h>
@embhorn

embhorn commented Sep 17, 2026

Copy link
Copy Markdown
Member

Hi @warter666

Thanks for bringing this to our attention. I am rolling these few fixes into a new PR: #620

Please submit issues rather than PR's, since we require a contributor agreement for third party changes.

Cheers,
@embhorn

@embhorn embhorn closed this Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants