From 039bae9710cbc1c4a6f6a24308359adb0f78e16e Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Tue, 8 Oct 2013 10:40:33 +0200 Subject: [PATCH] base: make FIFO elements zero-pointer save fix #904 --- base/include/util/fifo.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/base/include/util/fifo.h b/base/include/util/fifo.h index c20e5ea286..79302defd7 100644 --- a/base/include/util/fifo.h +++ b/base/include/util/fifo.h @@ -14,6 +14,8 @@ #ifndef _INCLUDE__UTIL__FIFO_H_ #define _INCLUDE__UTIL__FIFO_H_ +#include + namespace Genode { /* @@ -166,7 +168,17 @@ namespace Genode { Fifo_element(T *object) : _object(object) { } - inline T *object() { return _object; } + /** + * Get typed object pointer + * + * Zero-pointer save: Returns 0 if this pointer is 0 to + * cover the case of accessing an empty FIFO. + */ + inline T *object() + { + if (this) { return _object; } + return 0; + } }; }