Skip to content

Commit 737f6c2

Browse files
committed
Remove forced alignment in operators new and delete
This alignment prevents umm_malloc to detect buffer overruns which fall within padding introduced by new/new[]. Allocated memory will be aligned by design of umm_malloc, so we don't need to pad anything here. Also fixed some formatting/newlines and removed unused header files.
1 parent 6fc1417 commit 737f6c2

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

cores/esp8266/abi.cpp

+26-23
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,41 @@
1919
#include <stdlib.h>
2020
#include <assert.h>
2121
#include <debug.h>
22-
extern "C" {
23-
#include "ets_sys.h"
24-
#include "os_type.h"
25-
#include "osapi.h"
26-
#include "mem.h"
27-
}
2822
#include <Arduino.h>
2923
#include <cxxabi.h>
3024

3125
using __cxxabiv1::__guard;
3226

33-
void *operator new(size_t size) {
34-
size = ((size + 3) & ~((size_t)0x3));
35-
return os_malloc(size);
27+
void *operator new(size_t size)
28+
{
29+
return malloc(size);
3630
}
3731

38-
void *operator new[](size_t size) {
39-
size = ((size + 3) & ~((size_t)0x3));
40-
return os_malloc(size);
32+
void *operator new[](size_t size)
33+
{
34+
return malloc(size);
4135
}
4236

43-
void operator delete(void * ptr) {
44-
os_free(ptr);
37+
void operator delete(void * ptr)
38+
{
39+
free(ptr);
4540
}
4641

47-
void operator delete[](void * ptr) {
48-
os_free(ptr);
42+
void operator delete[](void * ptr)
43+
{
44+
free(ptr);
4945
}
5046

5147
extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
5248
extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__));
5349

54-
void __cxa_pure_virtual(void) {
50+
void __cxa_pure_virtual(void)
51+
{
5552
panic();
5653
}
5754

58-
void __cxa_deleted_virtual(void) {
55+
void __cxa_deleted_virtual(void)
56+
{
5957
panic();
6058
}
6159

@@ -87,20 +85,25 @@ extern "C" void __cxa_guard_abort(__guard* pg)
8785
}
8886

8987

90-
namespace std {
91-
void __throw_bad_function_call() {
88+
namespace std
89+
{
90+
void __throw_bad_function_call()
91+
{
9292
panic();
9393
}
9494

95-
void __throw_length_error(char const*) {
95+
void __throw_length_error(char const*)
96+
{
9697
panic();
9798
}
9899

99-
void __throw_bad_alloc() {
100+
void __throw_bad_alloc()
101+
{
100102
panic();
101103
}
102104

103-
void __throw_logic_error(const char* str) {
105+
void __throw_logic_error(const char* str)
106+
{
104107
panic();
105108
}
106109
}

0 commit comments

Comments
 (0)