Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3fe7c2e

Browse filesBrowse files
Add div by zero check back into WMath::map (espressif#4853)
* Add div by zero check back into WMath::map * include esp32-hal-log.h Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
1 parent 5d00b6e commit 3fe7c2e
Copy full SHA for 3fe7c2e

File tree

Expand file treeCollapse file tree

1 file changed

+5
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+5
-1
lines changed

‎cores/esp32/WMath.cpp

Copy file name to clipboardExpand all lines: cores/esp32/WMath.cpp
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern "C" {
2727
#include <stdlib.h>
2828
#include "esp_system.h"
2929
}
30+
#include "esp32-hal-log.h"
3031

3132
void randomSeed(unsigned long seed)
3233
{
@@ -69,7 +70,10 @@ long map(long x, long in_min, long in_max, long out_min, long out_max) {
6970
const long dividend = out_max - out_min;
7071
const long divisor = in_max - in_min;
7172
const long delta = x - in_min;
72-
73+
if(divisor == 0){
74+
log_e("Invalid map input range, min == max");
75+
return -1; //AVR returns -1, SAM returns 0
76+
}
7377
return (delta * dividend + (divisor / 2)) / divisor + out_min;
7478
}
7579

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.