tdb: Add overflow-checking tdb_add_off_t
[obnox/samba/samba-obnox.git] / lib / tdb / common / tdb.c
index a2ae187f57720f477877d258739d008cf1d3dc65..6256a05d04ebf53f7cd9913abaf713802fe95530 100644 (file)
@@ -1000,6 +1000,17 @@ bool tdb_write_all(int fd, const void *buf, size_t count)
        return true;
 }
 
+bool tdb_add_off_t(tdb_off_t a, tdb_off_t b, tdb_off_t *pret)
+{
+       tdb_off_t ret = a + b;
+
+       if ((ret < a) || (ret < b)) {
+               return false;
+       }
+       *pret = ret;
+       return true;
+}
+
 #ifdef TDB_TRACE
 static void tdb_trace_write(struct tdb_context *tdb, const char *str)
 {