Attached is a patch that might fix the warning. It appears that the
"put_time()" function is only used in spell.c, so I changed it to be an int
function, and tested its return value, and then tried to mimic how similar
errors are handled.
On Monday, March 2, 2015 at 1:53:47 PM UTC-6, Michael Jarvis wrote:
> This appears to have been in the code for a while, and it's a minor warning,
> but I thought I'd mention it.
>
> gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -Wall -Wextra -pipe -std=gnu99
> -DNDEBUG -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -o objects/misc2.o
> misc2.c
> misc2.c: In function 'put_time':
> misc2.c:6289: warning: ignoring return value of 'fwrite', declared with
> attribute warn_unused_result
>
>
> Looking at the code in question, we should probably be checking the return
> value of fwrite, but I'm not sure what the "best" solution would be to handle
> an error writing 8 bytes to the file handle.
>
> My suggestion would be to make this a non-void function.
>
> Here's the code in question with line numbers:
>
> src/misc2.c
>
> 6278 /*
> 6279 * Write time_t to file "fd" in 8 bytes.
> 6280 */
> 6281 void
> 6282 put_time(fd, the_time)
> 6283 FILE^I*fd;
> 6284 time_t^Ithe_time;
> 6285 {
> 6286 char_u^Ibuf[8];
> 6287
> 6288 time_to_bytes(the_time, buf);
> 6289 fwrite(buf, (size_t)8, (size_t)1, fd);
> 6290 }
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
ocadmin@majsimvm1:~/src/pub/vim-src/vim$ hg diff
diff -r 3af822eb4da5 src/misc2.c
--- a/src/misc2.c Sat Feb 28 13:11:45 2015 +0100
+++ b/src/misc2.c Mon Mar 02 14:27:46 2015 -0600
@@ -6277,8 +6277,9 @@
/*
* Write time_t to file "fd" in 8 bytes.
+ * Return 1 on error
*/
- void
+ int
put_time(fd, the_time)
FILE *fd;
time_t the_time;
@@ -6286,7 +6287,10 @@
char_u buf[8];
time_to_bytes(the_time, buf);
- fwrite(buf, (size_t)8, (size_t)1, fd);
+ if ((fwrite(buf, (size_t)8, (size_t)1, fd)) == 1)
+ return 0;
+ else
+ return 1;
}
/*
diff -r 3af822eb4da5 src/proto/misc2.pro
--- a/src/proto/misc2.pro Sat Feb 28 13:11:45 2015 +0100
+++ b/src/proto/misc2.pro Mon Mar 02 14:27:46 2015 -0600
@@ -105,7 +105,7 @@
time_t get8ctime __ARGS((FILE *fd));
char_u *read_string __ARGS((FILE *fd, int cnt));
int put_bytes __ARGS((FILE *fd, long_u nr, int len));
-void put_time __ARGS((FILE *fd, time_t the_time));
+int put_time __ARGS((FILE *fd, time_t the_time));
void time_to_bytes __ARGS((time_t the_time, char_u *buf));
int has_non_ascii __ARGS((char_u *s));
/* vim: set ft=c : */
diff -r 3af822eb4da5 src/spell.c
--- a/src/spell.c Sat Feb 28 13:11:45 2015 +0100
+++ b/src/spell.c Mon Mar 02 14:27:46 2015 -0600
@@ -8280,7 +8280,11 @@
/* Set si_sugtime and write it to the file. */
spin->si_sugtime = time(NULL);
- put_time(fd, spin->si_sugtime); /* <timestamp> */
+ if (put_time(fd, spin->si_sugtime)) /* <timestamp> */
+ {
+ retval=FAIL;
+ goto theend;
+ }
}
/* SN_NOSPLITSUGS: nothing
@@ -9006,7 +9010,11 @@
putc(VIMSUGVERSION, fd); /* <versionnr> */
/* Write si_sugtime to the file. */
- put_time(fd, spin->si_sugtime); /* <timestamp> */
+ if (put_time(fd, spin->si_sugtime)) /* <timestamp> */
+ {
+ EMSG(_(e_write));
+ goto theend;
+ }
/*
* <SUGWORDTREE>