Skip to content

Conversation

JackWilli
Copy link
Contributor

The fdInUse function passed in O_WRONLY | O_RDWR as flags and then checked fileFlags[fd] & flags == flags. This is only true if all of the bits set in flags are also set in fileFlags[fd]. Since O_WRONLY | O_RDWR are mutually exclusive the fdInUse function always returns false in this case and the write syscall fails.

I fixed the expression and passed in an enum instead to make it more explicit about what we are testing for.

Copy link
Owner

@mortbopet mortbopet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments - bonus points if you can also come up with a unit test to verify your changes :).

Comment on lines +199 to +201
return (fileFlags[fd] + 1) & 1; // LSB is 1 if the fd has read perms
}
return false;
return (fileFlags[fd] + 1) & 2; // 2nd LSB is 1 if the fd has write perms
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing arithmetic and bitwise logic is a bit too funky for me. I think these expressions can be rewritten using bit extracts and XORs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secondly, we should also extract out the nth LSB is X perms to an enum, e.g. something like

enum FilePermissions {
   RD_PERM_FLAG = 1 << 0,
   WR_PERM_FLAG = 1 << 1
};

@@ -84,6 +84,11 @@ class SystemIO : public QObject {
static constexpr int O_TRUNC = 0x00000400; // 1024
static constexpr int O_EXCL = 0x00000800; // 2048

enum Permission {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum class

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants