Skip to content

SX126x: refactor timeout parameter to use struct instead of raw array #1059

Description

@terrillmoore

Problem

setRx() takes u1_t timeout[SX126X_TIMEOUT_LEN] as a parameter, and SX126X_TIMEOUT_LEN is used in three separate places to construct timeout arrays before calling setRx(). This has two problems:

  1. DRY violation: the timeout array construction is repeated at each call site.
  2. Array-as-parameter pitfall: C decays u1_t timeout[SX126X_TIMEOUT_LEN] to u1_t *timeout, so sizeof(timeout) gives pointer size, not SX126X_TIMEOUT_LEN. This makes the code fragile if anyone adds a sizeof check or tries to validate the parameter.

Proposed fix

Define a struct:
```c
typedef struct {
u1_t bytes[SX126X_TIMEOUT_LEN];
} sx126x_timeout_t;
```

Change setRx() to take const sx126x_timeout_t *timeout, and update the three call sites. This makes the size self-documenting and prevents decay-to-pointer issues.

Files

  • src/lmic/radio_sx126x.c: setRx() definition and all call sites

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