From 4379e8f34f14ef8d73e85c86244b3c90358224f0 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Wed, 2 Oct 2019 06:35:08 +0000 Subject: [PATCH] dawn_wire: Only generate has_member for optional members We were generating has_member for all pointer members which meant it was possible to incorrectly pass nullptr for required arguments. Bug: chromium:1009166 Change-Id: I5e32bab5ccae010468e55897ae9840ab8fda684f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11760 Commit-Queue: Corentin Wallez Reviewed-by: Kai Ninomiya Reviewed-by: Corentin Wallez --- generator/templates/dawn_wire/WireCmd.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp index 2163763ef7..f9c6a448c9 100644 --- a/generator/templates/dawn_wire/WireCmd.cpp +++ b/generator/templates/dawn_wire/WireCmd.cpp @@ -106,7 +106,7 @@ size_t {{as_varName(member.name)}}Strlen; {% endfor %} - {% for member in members if member.annotation != "value" and member.type.category != "object" %} + {% for member in members if member.optional and member.annotation != "value" and member.type.category != "object" %} bool has_{{as_varName(member.name)}}; {% endfor %} }; @@ -187,9 +187,9 @@ {% for member in members if member.length == "strlen" %} {% set memberName = as_varName(member.name) %} - bool has_{{memberName}} = record.{{memberName}} != nullptr; - transfer->has_{{memberName}} = has_{{memberName}}; {% if member.optional %} + bool has_{{memberName}} = record.{{memberName}} != nullptr; + transfer->has_{{memberName}} = has_{{memberName}}; if (has_{{memberName}}) {% endif %} { @@ -257,8 +257,10 @@ {% for member in members if member.length == "strlen" %} {% set memberName = as_varName(member.name) %} - bool has_{{memberName}} = transfer->has_{{memberName}}; - if (has_{{memberName}}) + record->{{memberName}} = nullptr; + {% if member.optional %} + if (transfer->has_{{memberName}}) + {% endif %} { size_t stringLength = transfer->{{memberName}}Strlen; const char* stringInBuffer = nullptr; @@ -269,8 +271,6 @@ memcpy(copiedString, stringInBuffer, stringLength); copiedString[stringLength] = '\0'; record->{{memberName}} = copiedString; - } else { - record->{{memberName}} = nullptr; } {% endfor %}