From b92fa105572a598968764e578b95fe0b693c945b Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 25 Feb 2019 09:49:00 +0000 Subject: [PATCH] KnownObject: Make it an error to request ID 0 WebGPU error handling assumes non-optional objects point to valid objects. The wire code wasn't updated to produce an error when ID 0 is requested in the non-optional case. BUG=chromium:934360 Change-Id: I203d2ec864dabe0e76109e1932fc31cbf26291d7 Reviewed-on: https://dawn-review.googlesource.com/c/4980 Reviewed-by: Austin Eng Reviewed-by: Kai Ninomiya Reviewed-by: Corentin Wallez Commit-Queue: Corentin Wallez --- src/dawn_wire/server/ObjectStorage.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dawn_wire/server/ObjectStorage.h b/src/dawn_wire/server/ObjectStorage.h index 3405a88bf4..0da9e7ca76 100644 --- a/src/dawn_wire/server/ObjectStorage.h +++ b/src/dawn_wire/server/ObjectStorage.h @@ -60,12 +60,14 @@ namespace dawn_wire { namespace server { using Data = ObjectData; KnownObjects() { - // Pre-allocate ID 0 to refer to the null handle. - Data nullObject; - nullObject.handle = nullptr; - nullObject.valid = true; - nullObject.allocated = true; - mKnown.push_back(nullObject); + // Reserve ID 0 so that it can be used to represent nullptr for optional object values + // in the wire format. However don't tag it as allocated so that it is an error to ask + // KnownObjects for ID 0. + Data reservation; + reservation.handle = nullptr; + reservation.valid = false; + reservation.allocated = false; + mKnown.push_back(reservation); } // Get a backend objects for a given client ID.