kanflo / opendps

Give your DPS5005 the upgrade it deserves
MIT License
895 stars 124 forks source link

Dynamic memory usage? #174

Open Xenoamor opened 5 years ago

Xenoamor commented 5 years ago

Any ideas how the following code compiles? https://github.com/kanflo/opendps/blob/c1a8ab69d97ee3a329a2283ec88c49150537978c/opendps/uframe.h#L44 https://github.com/kanflo/opendps/blob/c1a8ab69d97ee3a329a2283ec88c49150537978c/opendps/uframe.h#L47-L52 https://github.com/kanflo/opendps/blob/c1a8ab69d97ee3a329a2283ec88c49150537978c/opendps/protocol_handler.c#L348-L351

I've never seen uint8_t buffer[variable]; compile before

Xenoamor commented 5 years ago

I've scrubbed this in #176 as I really didn't like the look of it

kanflo commented 5 years ago

I guess this is one of the places where a static allocation would be suitable.

Xenoamor commented 5 years ago

As far as I'm aware this isn't valid C at all. It still baffles me how it compiles

m-kozlowski commented 5 years ago

I think it is Well, sort of, because gcc is the only compiller I've used that has it implemented;)

Xenoamor commented 5 years ago

I had no idea this was a thing. Seems pretty dangerous to me if you're trying to avoid the heap