[ tvtime-Bugs-3484607 ] Declared with attribute warn_unused_result [-Wunused-result]
SourceForge.net <[email protected]> Sun, 05 Feb 2012 03:00:21 -0800
| Newsgroups | gmane.comp.video.tvtime.devel |
|---|---|
| Message-ID | <[email protected]> |
Bugs item #3484607, was opened at 2012-02-05 02:48
Message generated for change (Comment added) made by zradu
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=506987&aid=3484607&group_id=64301
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Pojar George (zradu)
Assigned to: Nobody/Anonymous (nobody)
Summary: Declared with attribute warn_unused_result [-Wunused-result]
Initial Comment:
-------------------------------------------------------------------------------------
int rtctimer_next_tick( rtctimer_t *rtctimer )
{
unsigned long rtc_data;
struct pollfd pfd;
pfd.fd = rtctimer->rtc_fd;
pfd.events = POLLIN | POLLERR;
again:
if( poll( &pfd, 1, 100000 ) < 0 ) {
if( errno == EINTR ) {
goto again;
}
if( rtctimer->verbose ) {
fprintf( stderr, "rtctimer: poll call failed: %s\n",
strerror( errno ) );
}
return 0;
}
read( rtctimer->rtc_fd, &rtc_data, sizeof( rtc_data ) );
return 1;
}
-------------------------------------------------------------------------------------
I compiled tvtime and the following warning popped up. One of them is:
-------------------------------------------------------------------------------------
rtctimer.c: In function 'rtctimer_next_tick':
rtctimer.c: warning: ignoring return value of 'read', declared with attribute warn_unused_result [-Wunused-result]
-------------------------------------------------------------------------------------
If you don't check what read returns, chances are very high that your program will fail unexpectedly if a read error does occur, and it will be impossible to debug.
Always check the return value of library calls, especially I/O ones since they do fail in normal circumstances.
Thancks.
----------------------------------------------------------------------
>Comment By: Pojar George (zradu)
Date: 2012-02-05 03:00
Message:
You're not checking the return value of read, which is a bug just waiting
to happen.
ssize_t r = read(rtctimer->rtc_fd, &rtc_data, sizeof( rtc_data ) );
if (r == -1) {
// deal with failed read
} else if (r != sizeof(rtc_data)) {
// you didn't read as much as you wanted to
...
If you don't check what read returns, chances are very high that your
program will fail unexpectedly if a read error does occur, and it will be
impossible to debug. (The second case might not apply in this specific
example, or for some pipe reads.)
Always check the return value of library calls, especially I/O ones since
they do fail in normal circumstances.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=506987&aid=3484607&group_id=64301
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2