diff --git a/src/node_file.h b/src/node_file.h index a65b9f0e5fcca9..bf277a0e433525 100644 --- a/src/node_file.h +++ b/src/node_file.h @@ -39,11 +39,11 @@ class FSReqBase : public ReqWrap { encoding_ = encoding; if (data != nullptr) { - CHECK_EQ(data_, nullptr); + CHECK(!has_data_); buffer_.AllocateSufficientStorage(len + 1); buffer_.SetLengthAndZeroTerminate(len); memcpy(*buffer_, data, len); - data_ = *buffer_; + has_data_ = true; } } @@ -54,17 +54,19 @@ class FSReqBase : public ReqWrap { virtual void SetReturnValue(const FunctionCallbackInfo& args) = 0; const char* syscall() const { return syscall_; } - const char* data() const { return data_; } + const char* data() const { return has_data_ ? *buffer_ : nullptr; } enum encoding encoding() const { return encoding_; } size_t self_size() const override { return sizeof(*this); } private: enum encoding encoding_ = UTF8; + bool has_data_ = false; const char* syscall_ = nullptr; - const char* data_ = nullptr; - MaybeStackBuffer buffer_; + // Typically, the content of buffer_ is something like a file name, so + // something around 64 bytes should be enough. + MaybeStackBuffer buffer_; DISALLOW_COPY_AND_ASSIGN(FSReqBase); };