pidl: Add max property to be used instead of range for unsigned types.
authorTim Prouty <tprouty@samba.org>
Thu, 15 Jan 2009 18:51:57 +0000 (10:51 -0800)
committerTim Prouty <tprouty@samba.org>
Thu, 15 Jan 2009 22:52:35 +0000 (14:52 -0800)
Compilers complain about ranges starting at 0 for unsigned types,
since an unsigned type is never less than 0.  The max property
implicitly makes 0 the lower bound when used with unsigned types.

pidl/lib/Parse/Pidl/Compat.pm
pidl/lib/Parse/Pidl/NDR.pm
pidl/lib/Parse/Pidl/Samba4/NDR/Parser.pm

index 1b49c439c43bd3fdc4b679c0838d4bd832000949..58ba136591b915c1e41ac80cafc924ea0bee62e0 100644 (file)
@@ -67,6 +67,7 @@ my %supported_properties = (
 
        # array
        "range"                 => ["ELEMENT"],
+       "max"                   => ["ELEMENT"],
        "size_is"               => ["ELEMENT"],
        "string"                => ["ELEMENT"],
        "noheader"              => ["ELEMENT"],
index 5ee26d16b68c76f611c4fedc832aab5671f513e1..89632437c10f74e1cd18d9cddb3c132cddde8be7 100644 (file)
@@ -921,6 +921,7 @@ my %property_list = (
 
        # array
        "range"                 => ["ELEMENT"],
+       "max"                   => ["ELEMENT"],
        "size_is"               => ["ELEMENT"],
        "string"                => ["ELEMENT"],
        "noheader"              => ["ELEMENT"],
index 0a4e44ef0ec256301403c4b768a9c32b76e638e0..e2b14c10b1e1c63f642678017ce2c08ff50f18cc 100644 (file)
@@ -862,6 +862,12 @@ sub ParseDataPull($$$$$$$)
                        $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");");
                        $self->pidl("}");
                }
+               if (my $max = has_property($e, "max")) {
+                       $var_name = get_value_of($var_name);
+                       $self->pidl("if ($var_name > $max) {");
+                       $self->pidl("\treturn ndr_pull_error($ndr, NDR_ERR_RANGE, \"value out of range\");");
+                       $self->pidl("}");
+               }
        } else {
                $self->ParseTypePull($l->{DATA_TYPE}, $ndr, $var_name, $primitives, $deferred);
        }