Skip to content

Conversation

stronnag
Copy link
Collaborator

@stronnag stronnag commented Jul 17, 2025

User description

gcc 15 generated warnings in osd.c:

[267/311] Building C object src/main/t...s/SITL.elf.dir/__/__/io/vtx_string.c.o
/home/jrh/Projects/inav/src/main/io/vtx_string.c:54:61: warning: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (7 chars into 6 available) [-Wunterminated-string-initialization]
   54 | const char vtx58BandLetter[VTX_STRING_5G8_BAND_COUNT + 1] = "-ABEFR";
      |                                                             ^~~~~~~~
/home/jrh/Projects/inav/src/main/io/vtx_string.c:76:62: warning: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (4 chars into 3 available) [-Wunterminated-string-initialization]
   76 | const char vtx1G3BandLetter[VTX_STRING_1G3_BAND_COUNT + 1] = "-AB";

Fix these warnings by using array of characters rather than strings.


PR Type

Bug fix


Description

This description is generated by an AI tool. It may have inaccuracies

  • Fix GCC 15 warnings for character array initialization

  • Replace string literals with character array initializers

  • Prevent NUL terminator truncation warnings


Diagram Walkthrough

flowchart LR
  A["String literal initialization"] --> B["Character array initialization"]
  B --> C["GCC 15 warnings resolved"]
Loading

File Walkthrough

Relevant files
Bug fix
vtx_string.c
Fix character array initialization warnings                           

src/main/io/vtx_string.c

  • Replace string literal initialization with character array syntax for
    vtx58BandLetter
  • Replace string literal initialization with character array syntax for
    vtx1G3BandLetter
  • Fix GCC 15 warnings about NUL terminator truncation
  • +2/-2     

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    ⚡ Recommended focus areas for review

    Missing Terminator

    The character arrays are declared with size VTX_STRING_5G8_BAND_COUNT + 1 and VTX_STRING_1G3_BAND_COUNT + 1 but are initialized without null terminators. This could cause issues if the arrays are used as C strings elsewhere in the code.

    const char vtx58BandLetter[VTX_STRING_5G8_BAND_COUNT + 1] = {'-', 'A', 'B', 'E', 'F', 'R'};
    
    const char * const vtx58ChannelNames[VTX_STRING_5G8_CHAN_COUNT + 1] = {
        "-", "1", "2", "3", "4", "5", "6", "7", "8",
    };
    
    const char * const vtx58DefaultPowerNames[VTX_STRING_5G8_POWER_COUNT + 1] = {
        "---", "PL1", "PL2", "PL3", "PL4", "PL5"
    };
    
    const uint16_t vtx1G3frequencyTable[VTX_STRING_1G3_BAND_COUNT][VTX_STRING_1G3_CHAN_COUNT] =
    {
        { 1080, 1120, 1160, 1200, 1240, 1280, 1320, 1360 }, // A
        { 1080, 1120, 1160, 1200, 1258, 1280, 1320, 1360 }, // B
    };
    
    const char * const vtx1G3BandNames[VTX_STRING_1G3_BAND_COUNT + 1] = {
        "-",
        "A",
        "B",
    };
    
    const char vtx1G3BandLetter[VTX_STRING_1G3_BAND_COUNT + 1] = {'-', 'A', 'B'};

    Copy link

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @stronnag
    Copy link
    Collaborator Author

    and FYI, following gcc's recommendation of using an __attibute__ breaks compiling the SITL on MacOS with clang.

    @DzikuVx DzikuVx requested a review from Copilot July 21, 2025 09:51
    Copy link
    Contributor

    @Copilot Copilot AI left a comment

    Choose a reason for hiding this comment

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

    Pull Request Overview

    This PR fixes GCC 15 compiler warnings related to character array initialization in vtx_string.c by replacing string literal initializers with explicit character array syntax to prevent NUL terminator truncation warnings.

    • Replace string literal initialization with character array syntax for vtx58BandLetter
    • Replace string literal initialization with character array syntax for vtx1G3BandLetter

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants