Skip to content

Endless loop in runtime_nrf.go: sleepTicks() #3356

Open
@temnok

Description

@temnok

Endless loop in runtime_nrf.go: sleepTicks() function can happen for parameter d >= 0x800000 (>= 256 seconds for 32768Hz ticks) because & 0x7fffff operation will return 0 for second and following loop runs and d variable remains unchanged:

Current version:

func sleepTicks(d timeUnit) {
	for d != 0 {
		ticks := uint32(d) & 0x7fffff // 23 bits (to be on the safe side)
		rtc_sleep(ticks)
		d -= timeUnit(ticks)
	}
}

Fixed version:

func sleepTicks(d timeUnit) {
	for d != 0 {
		ticks := uint32(d)
		if ticks > 0x7fffff { // 23 bits (to be on the safe side)
			ticks = 0x7fffff
		}
		rtc_sleep(ticks)
		d -= timeUnit(ticks)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnRFNordic Semi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions