pidl: Print proper errors when arrays don't have a specified size rather than spewing...
authorJelmer Vernooij <jelmer@samba.org>
Sun, 19 Jul 2009 18:42:52 +0000 (20:42 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 19 Jul 2009 18:42:52 +0000 (20:42 +0200)
pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm
pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm

index ed1b71a236f7767405900d99099af5ecf573ef13..a2a61d87d07319546e54ea1b6988304bea577282 100644 (file)
@@ -96,11 +96,17 @@ sub ParseOutputArgument($$$)
                # structure, the user should be able to know the size beforehand 
                # to allocate a structure of the right size.
                my $env = GenerateFunctionInEnv($fn, "r.");
-               my $size_is = ParseExpr($e->{LEVELS}[$level]->{SIZE_IS}, $env, $e->{ORIGINAL});
-               if (has_property($e, "charset")) {
-                   $self->pidl("memcpy(CONST_DISCARD(char *, $e->{NAME}), r.out.$e->{NAME}, $size_is * sizeof(*$e->{NAME}));");
+               my $l = $e->{LEVELS}[$level];
+               unless (defined($l->{SIZE_IS})) {
+                       error($e->{ORIGINAL}, "no size known for [out] array `$e->{NAME}'");
+                       $self->pidl('#error No size known for [out] array `$e->{NAME}');
                } else {
-                   $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is * sizeof(*$e->{NAME}));");
+                       my $size_is = ParseExpr($l->{SIZE_IS}, $env, $e->{ORIGINAL});
+                       if (has_property($e, "charset")) {
+                               $self->pidl("memcpy(CONST_DISCARD(char *, $e->{NAME}), r.out.$e->{NAME}, $size_is * sizeof(*$e->{NAME}));");
+                       } else {
+                               $self->pidl("memcpy($e->{NAME}, r.out.$e->{NAME}, $size_is * sizeof(*$e->{NAME}));");
+                       }
                }
        } else {
                $self->pidl("*$e->{NAME} = *r.out.$e->{NAME};");
index c9a8eea59fd146f17192da43a68e4b3b9440383d..5599de9d790904692ee2b215859f8957f603e584 100644 (file)
@@ -11,7 +11,7 @@ use Exporter;
 @EXPORT_OK = qw(DeclLevel);
 
 use strict;
-use Parse::Pidl qw(warning fatal);
+use Parse::Pidl qw(warning error fatal);
 use Parse::Pidl::Typelist qw(mapTypeName scalar_is_reference);
 use Parse::Pidl::Util qw(ParseExpr has_property is_constant);
 use Parse::Pidl::NDR qw(GetNextLevel);
@@ -72,8 +72,13 @@ sub AllocOutVar($$$$$)
        }
 
        if ($l->{TYPE} eq "ARRAY") {
-               my $size = ParseExpr($l->{SIZE_IS}, $env, $e);
-               pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);";
+               unless(defined($l->{SIZE_IS})) {
+                       error($e->{ORIGINAL}, "No size known for array `$e->{NAME}'");
+                       pidl "#error No size known for array `$e->{NAME}'";
+               } else {
+                       my $size = ParseExpr($l->{SIZE_IS}, $env, $e);
+                       pidl "$name = talloc_zero_array($mem_ctx, " . DeclLevel($e, 1) . ", $size);";
+               }
        } else {
                pidl "$name = talloc_zero($mem_ctx, " . DeclLevel($e, 1) . ");";
        }