mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:28:11 +00:00
Everywhere: Prevent risky implicit casts of (Nonnull)RefPtr
Our existing implementation did not check the element type of the other pointer in the constructors and move assignment operators. This meant that some operations that would require explicit casting on raw pointers were done implicitly, such as: - downcasting a base class to a derived class (e.g. `Kernel::Inode` => `Kernel::ProcFSDirectoryInode` in Kernel/ProcFS.cpp), - casting to an unrelated type (e.g. `Promise<bool>` => `Promise<Empty>` in LibIMAP/Client.cpp) This, of course, allows gross violations of the type system, and makes the need to type-check less obvious before downcasting. Luckily, while adding the `static_ptr_cast`s, only two truly incorrect usages were found; in the other instances, our casts just needed to be made explicit.
This commit is contained in:
parent
bad23e3f8c
commit
d7b6cc6421
21 changed files with 43 additions and 43 deletions
|
@ -26,7 +26,7 @@ public:
|
|||
virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); };
|
||||
virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, FileDescription*) { return EROFS; }
|
||||
|
||||
virtual NonnullRefPtr<Inode> to_inode(SysFS const&) const;
|
||||
virtual NonnullRefPtr<SysFSInode> to_inode(SysFS const&) const;
|
||||
|
||||
InodeIndex component_index() const { return m_component_index; };
|
||||
|
||||
|
@ -45,7 +45,7 @@ public:
|
|||
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
||||
|
||||
virtual NonnullRefPtr<Inode> to_inode(SysFS const& sysfs_instance) const override final;
|
||||
virtual NonnullRefPtr<SysFSInode> to_inode(SysFS const& sysfs_instance) const override final;
|
||||
|
||||
protected:
|
||||
explicit SysFSDirectory(StringView name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue