summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2008-09-19 09:11:42 -0700
committerNathan Binkert <nate@binkert.org>2008-09-19 09:11:42 -0700
commitea83cedcf625c35ddc6fe6b9390cdd1cca6b2039 (patch)
tree083da1af8d314dcb20a8d2f76c088247e5416bbf /src
parentf066db7fcd49d2234178e5d80db9278c798d9ba8 (diff)
downloadgem5-ea83cedcf625c35ddc6fe6b9390cdd1cca6b2039.tar.xz
Check the return value of I/O operations for failure
Diffstat (limited to 'src')
-rwxr-xr-xsrc/base/loader/hex_file.cc4
-rw-r--r--src/base/remote_gdb.cc6
-rw-r--r--src/dev/ethertap.cc8
3 files changed, 13 insertions, 5 deletions
diff --git a/src/base/loader/hex_file.cc b/src/base/loader/hex_file.cc
index 17347531e..61d6c8009 100755
--- a/src/base/loader/hex_file.cc
+++ b/src/base/loader/hex_file.cc
@@ -65,7 +65,9 @@ HexFile::loadSections(Port *memPort)
Addr MemAddr;
uint32_t Data;
while (!feof(fp)) {
- fgets(Line, 64, fp);
+ char *ret = fgets(Line, sizeof(Line), fp);
+ if (!ret)
+ panic("malformed file");
parseLine(Line, &MemAddr, &Data);
if (MemAddr != 0) {
// Now, write to memory
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc
index fe4bdad5a..93d86447e 100644
--- a/src/base/remote_gdb.cc
+++ b/src/base/remote_gdb.cc
@@ -346,14 +346,16 @@ uint8_t
BaseRemoteGDB::getbyte()
{
uint8_t b;
- ::read(fd, &b, 1);
+ if (::read(fd, &b, 1) != 1)
+ warn("could not read byte from debugger");
return b;
}
void
BaseRemoteGDB::putbyte(uint8_t b)
{
- ::write(fd, &b, 1);
+ if (::write(fd, &b, 1) != 1)
+ warn("could not write byte to debugger");
}
// Send a packet to gdb
diff --git a/src/dev/ethertap.cc b/src/dev/ethertap.cc
index c7b292c8a..f1fd1800b 100644
--- a/src/dev/ethertap.cc
+++ b/src/dev/ethertap.cc
@@ -182,8 +182,12 @@ EtherTap::recvPacket(EthPacketPtr packet)
DPRINTF(Ethernet, "EtherTap output len=%d\n", packet->length);
DDUMP(EthernetData, packet->data, packet->length);
uint32_t len = htonl(packet->length);
- write(socket, &len, sizeof(len));
- write(socket, packet->data, packet->length);
+ ssize_t ret = write(socket, &len, sizeof(len));
+ if (ret != sizeof(len))
+ return false;
+ ret = write(socket, packet->data, packet->length);
+ if (ret != packet->length)
+ return false;
interface->recvDone();