|
23 | 23 | */
|
24 | 24 |
|
25 | 25 | #include "FS.h"
|
| 26 | +#undef max |
| 27 | +#undef min |
26 | 28 | #include "FSImpl.h"
|
27 | 29 | #include "spiffs/spiffs.h"
|
28 | 30 | #include "debug.h"
|
| 31 | +#include <limits> |
29 | 32 |
|
30 | 33 | extern "C" {
|
31 | 34 | #include "c_types.h"
|
@@ -119,6 +122,27 @@ class SPIFFSImpl : public FSImpl {
|
119 | 122 | config.log_block_size = _blockSize;
|
120 | 123 | config.log_page_size = _pageSize;
|
121 | 124 |
|
| 125 | + |
| 126 | + if (((uint32_t) std::numeric_limits<spiffs_block_ix>::max()) < (_size / _blockSize)) { |
| 127 | + DEBUGV("spiffs_block_ix type too small"); |
| 128 | + abort(); |
| 129 | + } |
| 130 | + |
| 131 | + if (((uint32_t) std::numeric_limits<spiffs_page_ix>::max()) < (_size / _pageSize)) { |
| 132 | + DEBUGV("spiffs_page_ix type too small"); |
| 133 | + abort(); |
| 134 | + } |
| 135 | + |
| 136 | + if (((uint32_t) std::numeric_limits<spiffs_obj_id>::max()) < (2 + (_size / (2*_pageSize))*2)) { |
| 137 | + DEBUGV("spiffs_obj_id type too small"); |
| 138 | + abort(); |
| 139 | + } |
| 140 | + |
| 141 | + if (((uint32_t) std::numeric_limits<spiffs_span_ix>::max()) < (_size / _pageSize - 1)) { |
| 142 | + DEBUGV("spiffs_span_ix type too small"); |
| 143 | + abort(); |
| 144 | + } |
| 145 | + |
122 | 146 | // hack: even though fs is not initialized at this point,
|
123 | 147 | // SPIFFS_buffer_bytes_for_cache uses only fs->config.log_page_size
|
124 | 148 | // suggestion: change SPIFFS_buffer_bytes_for_cache to take
|
@@ -381,8 +405,8 @@ extern "C" uint32_t _SPIFFS_page;
|
381 | 405 | extern "C" uint32_t _SPIFFS_block;
|
382 | 406 |
|
383 | 407 | static SPIFFSImpl s_defaultFs(
|
384 |
| - (uint32_t) &_SPIFFS_start - 0x40200000, |
385 |
| - (uint32_t) (&_SPIFFS_end - &_SPIFFS_start), |
| 408 | + (uint32_t) (&_SPIFFS_start) - 0x40200000, |
| 409 | + (uint32_t) (&_SPIFFS_end) - (uint32_t) (&_SPIFFS_start), |
386 | 410 | (uint32_t) &_SPIFFS_page,
|
387 | 411 | (uint32_t) &_SPIFFS_block,
|
388 | 412 | 5);
|
|
0 commit comments