Skip to content

[BUG] Pointless String Length in prvCreateDNSMessage() Leads to Compiler Warning/ErrorΒ #1217

@StefanBalt

Description

@StefanBalt

Describe the bug

GCC (with strict settings) raises the following error

error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]

for the line below

( void ) strncpy( ( char * ) &( pucUDPPayloadBuffer[ uxIndex ] ), pcHostName, strlen( pcHostName ) + 1U );

and it is not wrong. Why use strncpy() if we do not have a useful length parameter in this scope?

I see 3 possible fixes:

  1. Keep track of the destination buffer size after it is allocated in prvGetPayloadBuffer()
  2. Use strcpy() again (revert change from 4c4223a)
  3. Use memcpy()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions