From 79a9701f63b8cef7e227cef96fd24ef834ce3045 Mon Sep 17 00:00:00 2001 From: m-holger Date: Thu, 7 Aug 2025 22:19:14 +0100 Subject: [PATCH] Refactor `QPDFFormFieldObjectHelper`: streamline checkbox and radio button value validation, improve readability, and reduce redundancy in type checks. --- libqpdf/QPDFFormFieldObjectHelper.cc | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/libqpdf/QPDFFormFieldObjectHelper.cc b/libqpdf/QPDFFormFieldObjectHelper.cc index e588861..2f990bc 100644 --- a/libqpdf/QPDFFormFieldObjectHelper.cc +++ b/libqpdf/QPDFFormFieldObjectHelper.cc @@ -304,25 +304,26 @@ QPDFFormFieldObjectHelper::setV(QPDFObjectHandle value, bool need_appearances) { if (getFieldType() == "/Btn") { if (isCheckbox()) { - bool okay = false; - if (value.isName()) { - std::string name = value.getName(); - okay = true; - // Accept any value other than /Off to mean checked. Files have been seen that use - // /1 or other values. - setCheckBoxValue((name != "/Off")); - } - if (!okay) { + if (!value.isName()) { warn("ignoring attempt to set a checkbox field to a value whose type is not name"); + return; } - } else if (isRadioButton()) { - if (value.isName()) { - setRadioButtonValue(value); - } else { + std::string name = value.getName(); + // Accept any value other than /Off to mean checked. Files have been seen that use + // /1 or other values. + setCheckBoxValue(name != "/Off"); + return; + } + if (isRadioButton()) { + if (!value.isName()) { warn( "ignoring attempt to set a radio button field to an object that is not a name"); + return; } - } else if (isPushbutton()) { + setRadioButtonValue(value); + return; + } + if (isPushbutton()) { warn("ignoring attempt set the value of a pushbutton field"); } return; -- libgit2 0.21.4