fix null deref on moved Cow

error_handling v0.1.5
Avril 4 years ago
parent 1672250ed6
commit fcd0597dc8
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -5,7 +5,7 @@ PROJECT=cow
AUTHOR=Avril (Flanchan) <flanchan@cumallover.me> AUTHOR=Avril (Flanchan) <flanchan@cumallover.me>
VERSION_MAJOR=0 VERSION_MAJOR=0
VERSION_MINOR=1.4 VERSION_MINOR=1.5
VERSION=$(VERSION_MAJOR).$(VERSION_MINOR) VERSION=$(VERSION_MAJOR).$(VERSION_MINOR)
ifeq ($(PREFIX),) ifeq ($(PREFIX),)

@ -16,8 +16,14 @@ struct Cow : public _cow_util::Span<unsigned char> {
virtual Fake clone() const; virtual Fake clone() const;
inline void* area() override { return cow_ptr(get_raw()); } inline void* area() override {
inline const void* area() const override { return cow_ptr_of(const void, get_raw()); } auto raw = get_raw();
return raw ? cow_ptr(raw) : nullptr;
}
inline const void* area() const override {
auto raw = get_raw();
return raw ? cow_ptr_of(const void, raw) : nullptr;
}
/// Get the size of the mapped area. /// Get the size of the mapped area.
/// ///

@ -37,11 +37,11 @@ Cow::~Cow(){}
Cow Cow::from_raw(cow_t* owned) { if(cow_is_fake(owned)) throw "Trying to create real from fake raw"; else return Cow(owned); } Cow Cow::from_raw(cow_t* owned) { if(cow_is_fake(owned)) throw "Trying to create real from fake raw"; else return Cow(owned); }
Cow::Fake Cow::clone() const { return Fake::from_real(*this); } Cow::Fake Cow::clone() const { return Fake::from_real(*this); }
cow_t* Cow::get_raw() const { return super->ptr(); } cow_t* Cow::get_raw() const { return super ? super->ptr() : nullptr; }
size_t Cow::size() const { return super->cow.size; } size_t Cow::size() const { return super ? super->cow.size : 0; }
cow_t* Cow::raw() const { return &super->cow; } cow_t* Cow::raw() const { return super ? &super->cow : nullptr; }
Cow::Fake::Fake(const Cow& copy) : Cow(copy), fake(cow_clone(copy.super->ptr())){} Cow::Fake::Fake(const Cow& copy) : Cow(copy), fake(cow_clone(copy.super->ptr())){}
Cow::Fake::Fake(const Fake& copy) : Cow(copy), fake(cow_clone(copy.fake)){}//Fake(*static_cast<const Cow*>(&copy)){} Cow::Fake::Fake(const Fake& copy) : Cow(copy), fake(cow_clone(copy.fake)){}//Fake(*static_cast<const Cow*>(&copy)){}

Loading…
Cancel
Save