Skip to content

Commit 2f7d34a

Browse files
committed
Replace assert() by Error_Handler()
Avoid to include "assert.h" which relies on printf(). This allow to save space: Example for CardInfo.ino sketche for the same target: - with assert: Sketch uses 35308 bytes (6%) of program storage space. Maximum is 524288 bytes. Global variables use 2384 bytes (1%) of dynamic memory, leaving 128688 bytes for local variables. Maximum is 131072 bytes. - without assert: Sketch uses 31844 bytes (6%) of program storage space. Maximum is 524288 bytes. Global variables use 2284 bytes (1%) of dynamic memory, leaving 128788 bytes for local variables. Maximum is 131072 bytes. Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 3703061 commit 2f7d34a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/SD.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ extern "C" {
5353
#include <inttypes.h>
5454
#include "stm32_def.h"
5555
}
56-
#include "assert.h"
5756
#include "STM32SD.h"
5857
SDClass SD;
5958

@@ -183,7 +182,9 @@ File::File()
183182
{
184183
_name = NULL;
185184
_fil = (FIL *)malloc(sizeof(FIL));
186-
assert(_fil != NULL);
185+
if (_fil == NULL) {
186+
Error_Handler();
187+
}
187188
#if _FATFS == 68300
188189
_fil->obj.fs = 0;
189190
_dir.obj.fs = 0;
@@ -196,10 +197,14 @@ File::File()
196197
File::File(const char *name)
197198
{
198199
_name = (char *)malloc(strlen(name) + 1);
199-
assert(_name != NULL);
200+
if (_name == NULL) {
201+
Error_Handler();
202+
}
200203
sprintf(_name, "%s", name);
201204
_fil = (FIL *)malloc(sizeof(FIL));
202-
assert(_fil != NULL);
205+
if (_fil == NULL) {
206+
Error_Handler();
207+
}
203208
#if _FATFS == 68300
204209
_fil->obj.fs = 0;
205210
_dir.obj.fs = 0;
@@ -578,7 +583,9 @@ char *File::name()
578583
uint8_t File::isDirectory()
579584
{
580585
FILINFO fno;
581-
assert(_name != NULL);
586+
if (_name == NULL) {
587+
Error_Handler();
588+
}
582589
#if _FATFS == 68300
583590
if (_dir.obj.fs != 0)
584591
#else

0 commit comments

Comments
 (0)