Change type of function pointer #66

Closed
opened 2024-02-18 17:59:06 +00:00 by nitori · 3 comments
Owner

The return types of read(2) and write(2) are actually ssize_t and not int.
This causes a compilation error on clang, but just a warning on gcc.
I can't create a pull request so here's a diff:

diff --git a/src/dj.c b/src/dj.c
index d5bd59c..8a982fa 100644
--- a/src/dj.c
+++ b/src/dj.c
@@ -199,7 +199,7 @@ Io_fdopen(struct Io *io, char *fn){
  * be set to zero to indicate the seek occurred. */
 static int
 Io_fdseek(struct Io *io){
-       int (*op)(int, void *, size_t);
+       ssize_t (*op)(int, void *, size_t);

        if(!fdisstd(io->fd) && lseek(io->fd, io->seek, SEEK_SET) != -1)
                return -1;
@@ -209,7 +209,7 @@ Io_fdseek(struct Io *io){
                 * likewise, because the parameters to read or write are going to be
                 * the same either way, just use a function pointer to keep track of
                 * the intended operation. */
-               op = (int (*)(int, void *, size_t))&write;
+               op = (ssize_t (*)(int, void *, size_t))&write;
                /* Function pointer casts are risky; this works because the difference
                 * is in the second parameter and only that write(2) makes the buffer
                 * const whereas read(2) does not. To avoid even the slightest
The return types of `read(2)` and `write(2)` are actually `ssize_t` and not `int`. This causes a compilation error on clang, but just a warning on gcc. I can't create a pull request so here's a diff: ```diff diff --git a/src/dj.c b/src/dj.c index d5bd59c..8a982fa 100644 --- a/src/dj.c +++ b/src/dj.c @@ -199,7 +199,7 @@ Io_fdopen(struct Io *io, char *fn){ * be set to zero to indicate the seek occurred. */ static int Io_fdseek(struct Io *io){ - int (*op)(int, void *, size_t); + ssize_t (*op)(int, void *, size_t); if(!fdisstd(io->fd) && lseek(io->fd, io->seek, SEEK_SET) != -1) return -1; @@ -209,7 +209,7 @@ Io_fdseek(struct Io *io){ * likewise, because the parameters to read or write are going to be * the same either way, just use a function pointer to keep track of * the intended operation. */ - op = (int (*)(int, void *, size_t))&write; + op = (ssize_t (*)(int, void *, size_t))&write; /* Function pointer casts are risky; this works because the difference * is in the second parameter and only that write(2) makes the buffer * const whereas read(2) does not. To avoid even the slightest ```
Owner

I should just drop the function pointer magic and use an if - working around type differences there (on which this is further elaborated in the surrounding comments) has caused me enough grief as-is.

I should just drop the function pointer magic and use an `if` - working around type differences there (on which this is further elaborated in the surrounding comments) has caused me enough grief as-is.
trinity added the
bug
label 2024-02-18 20:41:26 +00:00
trinity self-assigned this 2024-02-18 20:41:31 +00:00
Owner

On a side note - you can't create a pull request? Is this issue on your end or ours?

On a side note - you can't create a pull request? Is this issue on your end or ours?
Owner

Could you test the pull request and confirm it builds?

Could you test the pull request and confirm it builds?
emma closed this issue 2024-03-19 03:03:37 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: bonsai/coreutils#66
No description provided.