This is an archive of the discontinued LLVM Phabricator instance.

[LibFuzzer] Fix GCC `-Wunused-result` warning
Needs ReviewPublic

Authored by delcypher on Jul 11 2017, 4:05 AM.

Details

Reviewers
kcc
eugenis
Summary

[LibFuzzer] Fix GCC -Wunused-result warning in
Fuzzer::RawPrint(const char*) and make the implementation more robust by handling partial writes.

The warning was

./FuzzerIOPosix.cpp:118:29: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result [-Wunused-result]
   write(2, Str, strlen(Str));

Diff Detail

Event Timeline

delcypher created this revision.Jul 11 2017, 4:05 AM
kcc edited edge metadata.Jul 11 2017, 8:09 AM

I understand why this is desired in theory, but do we hit any related problem in practice?
If so, is a test possible?

In D35245#805183, @kcc wrote:

I understand why this is desired in theory, but do we hit any related problem in practice?
If so, is a test possible?

I've not hit problems in practice. My only real aim was to fix the warning. We could just do

(void) write(2, Str, strlen(str));

instead to suppress the warning. This is "technically wrong" though due to the possibility of not all the bytes of Str being written. So I thought I'd code up my solution to that.

I would understand if you don't want to use because it does over complicated the code without any (so far) observable benefit.

joerg added a subscriber: joerg.Jul 11 2017, 11:52 AM

A better construct would be to compute the full length and change both it and Str in the loop. No point in the complex arithmetic. I generally do prefer this as it improves interaction with pipes etc.