}
...
}
+
~BadFileDescriptorWrapper()
{
if (d_fd > 0) {
d_fd = -1;
}
}
+
int getHandle() const
{
return d_fd;
}
+
private:
- int d_fd{-1};
+ int d_fd{-1};
};
```
```C++
auto ptr = std::make_shared<int>(4);
for (auto idx = 0; idx < 10 ; idx++){
- std::thread([ptr]{ auto copy = ptr; }).detach(); //ok, only mutates the control block
+ std::thread([ptr]{ auto copy = ptr; }).detach(); // ok, only mutates the control block
}
```
std::thread threadA([&ptr]{
ptr = std::make_shared<int>(10);
});
+
std::thread threadB([&ptr]{
ptr = std::make_shared<int>(20);
});
if (length < 4) {
return;
}
+
/* read the first two bytes which hold the length of the next record */
uint16_t recordLen = data[0] * 256 + data[1];
+
/* let's assume that recordLen is equal to 65535 */
uint16_t totalRecordLen = /* size of the type */ sizeof(uint16_t) + recordLen; // <-- this results in a wrapped value of 65535 + 2 = 65537 = 1
if (totalRecordLen > length) {
return;
}
+
/* ... */
}
```
if (length < 4) {
return;
}
+
/* read the first two bytes which hold the length of the next record */
uint16_t recordLen = data[0] * 256 + data[1];
if (recordLen > length || (length - recordLen) < sizeof(uint16_t)) {
return;
}
+
/* ... */
}
```
{
d_fd = fopen(..);
}
+
~Child()
{
if (d_fd) {
f_fd = nullptr;
}
}
+
void doVirtualCall() override;
};
}
virtual void doVirtualCall();
+
private:
FILE* d_fd{nullptr};
};