Skip to content

RTC.begin() crashes whole processor #88

Closed
@maxgerhardt

Description

@maxgerhardt

This function is declared to have return value bool

bool RTClock::begin() {
if(openRtc()) {
is_initialized = true;
}
else {
is_initialized = false;
}
}

but there's not a single return keyword in that function. It ought to do return is_initialized; at the end.

This incorrect code causes some compilers (arm-none-eabi-gcc 10.3.1) to emit assembly that causes an infinite loop. Any sketch using RTC.begin(); deadlocks forever. Specifically, the assembly is

69eaa3dda954d333495272a5404b777435d6a9a7

(Notice how there is no pop {..., pc} to facilitate any returning in that function. After writing true, the code immediately writes false and jumps back to the beginingo of the code that writes false, thus being stuck forever at that line of C++ code). When I fix the code

eaed625b41282401253b94e15c48a04dd1e1fdcd

It does nicely return.

This code is undefined behavior which does happpen to work on the compiler version used in the Arduino IDE (7.0.1), however, the higher version one used in PlatformIO (10.3.1) breaks with it. (We upgraded it because, what could possible go wrong? Well, this). And of course, if this core ever decides to upgrade its compiler, this unfixed code is a ticking timebomb.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions