Fluorohydride / ygopro-core

ygopro script engine.
MIT License
321 stars 135 forks source link

fix buffer read/write #576

Closed salix5 closed 4 months ago

salix5 commented 5 months ago

https://gist.github.com/shafik/848ae25ee209f698763cffee272a58f8 According to the strict aliasing rule, we should not cast a pointer should to another type and dereference. It can be done by memcpy.

C++14 3.10, paragraph 10

If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined: —(10.1) the dynamic type of the object, —(10.2) a cv-qualified version of the dynamic type of the object, —(10.3) a type similar (as defined in 4.4) to the dynamic type of the object, —(10.4) a type that is the signed or unsigned type corresponding to the dynamic type of the object, —(10.5) a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of the object, —(10.6) an aggregate or union type that includes one of the aforementioned types among its elements or non- static data members (including, recursively, an element or non-static data member of a subaggregate or contained union), —(10.7) a type that is a (possibly cv-qualified) base class type of the dynamic type of the object, —(10.8) a char or unsigned char type.

Add buffer.h

Reference: https://github.com/edo9300/edopro/blame/master/gframe/bufferio.h

salix5 commented 4 months ago

@mercury233 @purerosefallen Can we merge this one?

purerosefallen commented 4 months ago

I doubt if reconnecting works

salix5 commented 4 months ago

I only changed buffer writing to the way it should be. I don't think it will change reconnecting.