Skip to content

Use of undefined behavior #287

Closed
@henrygab

Description

@henrygab

FAILING TO FIX THIS RESULTS IN WARNINGS OF POTENTIAL UNDEFINED BEHAVIOR.

This should not be worked around by casting to void*.

The open question: What causes DmacDescriptor to not be considered trivially copyable?

GCC warning of undefined behavior

...\libraries\SPI\SPI.cpp:
      In member function 'void SPIClass::dmaAllocate()':
...\libraries\SPI\SPI.cpp:
      Line 338 Char 37
      warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct DmacDescriptor' with no trivial copy-assignment [-Wclass-memaccess]
  338 |               sizeof(DmacDescriptor));
      |                                     ^
...\libraries\SPI\SPI.cpp:
      Line 342 Char 37
      warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct DmacDescriptor' with no trivial copy-assignment [-Wclass-memaccess]
  342 |               sizeof(DmacDescriptor));
      |                                     ^
In file included from ...\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:253,
                 from ...\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69,
                 from ...\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd.h:105,
                 from ...\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/sam.h:540,
                 from ...\cores\arduino/Arduino.h:48,
                 from ...\libraries\SPI\SPI.h:23,
                 from ...\libraries\SPI\SPI.cpp:20:
...\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/samd21/include/component/dmac.h:1070:16:
      note: 'struct DmacDescriptor' declared here
 1070 | typedef struct {
      |                ^

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