From 54a2f51d57a24104f1facff2674b4d441cdfde48 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 19 Jul 2009 20:42:52 +0200 Subject: pidl: Print proper errors when arrays don't have a specified size rather than spewing pages of perl warnings. --- pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm | 14 ++++++++++---- pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm | 11 ++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'pidl/lib/Parse/Pidl/Samba3') diff --git a/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm b/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm index ed1b71a236..a2a61d87d0 100644 --- a/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm +++ b/pidl/lib/Parse/Pidl/Samba3/ClientNDR.pm @@ -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};"); diff --git a/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm b/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm index c9a8eea59f..5599de9d79 100644 --- a/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm +++ b/pidl/lib/Parse/Pidl/Samba3/ServerNDR.pm @@ -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) . ");"; } -- cgit