]> git.earman.xyz Git - sensor-watch.git/commit
faces/totp: remove dynamic memory allocation
authorMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Mon, 18 Mar 2024 13:41:06 +0000 (10:41 -0300)
committerMatheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Mon, 18 Mar 2024 14:40:55 +0000 (11:40 -0300)
commit3f850d79c8b0b4da5c1b8854f2e6437ca163edc4
treee4fabde54328b8ac5bbab443dc2af4e77e30f0ff
parentdf38c262b80151af06f15e6a1a8899c51dec438e
faces/totp: remove dynamic memory allocation

Allocate an unlimited extent 128 byte buffer once during setup
instead of allocating and deallocating repeatedly. A static buffer
was not used because it fails to be reentrant and prevents multiple
instances of the watch face to be compiled by the user.

The advantage is the complete prevention of memory management errors,
improving the reliability of the watch. It also eliminates the overhead
of the memory allocator itself since malloc is not free.
The disadvantage is a worst case default size of 128 bytes was required,
meaning about 90 bytes will be wasted in the common case since most keys
are not that big. This can be overridden by the user via preprocessor.

The key lengths are checked on TOTP watch face initialization
and if any key is found to be too large to fit the buffer
it is turned off and the label and ERROR is displayed instead.

The base32 encoded secrets are decoded dynamically to the buffer
at the following times:

 - Face enters the foreground
 - User switches TOTP code

Therefore, there is still some extra runtime overhead
that can still be eliminated by code generation.
This will be addressed in future commits.

Tested-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Tested-on-hardware-by: madhogs <59648482+madhogs@users.noreply.github.com>
Signed-off-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
GitHub-Pull-Request: https://github.com/joeycastillo/Sensor-Watch/pull/385
movement/watch_faces/complication/totp_face.c