From: Jürg Billeter Date: Wed, 1 Aug 2012 09:39:40 +0000 (+0200) Subject: codegen: Fix va_start argument in methods throwing errors X-Git-Tag: 0.17.4~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3cda0bdebb78d57b357ca784265cea3dd810d7f7;p=thirdparty%2Fvala.git codegen: Fix va_start argument in methods throwing errors Fixes bug 620673. --- diff --git a/ccode/valaccodefunction.vala b/ccode/valaccodefunction.vala index ddbc8121e..d54215b13 100644 --- a/ccode/valaccodefunction.vala +++ b/ccode/valaccodefunction.vala @@ -1,6 +1,6 @@ /* valaccodefunction.vala * - * Copyright (C) 2006-2010 Jürg Billeter + * Copyright (C) 2006-2012 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -80,6 +80,14 @@ public class Vala.CCodeFunction : CCodeNode { parameters.insert (position, param); } + public int get_parameter_count () { + return parameters.size; + } + + public CCodeParameter get_parameter (int position) { + return parameters[position]; + } + /** * Returns a copy of this function. * diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 4762f574d..ba30e4f1b 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -1,6 +1,6 @@ /* valaccodebasemodule.vala * - * Copyright (C) 2006-2011 Jürg Billeter + * Copyright (C) 2006-2012 Jürg Billeter * Copyright (C) 2006-2008 Raffaele Sandrini * * This library is free software; you can redistribute it and/or @@ -4377,7 +4377,14 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } last_param = param; } - creation_call.add_argument (new CCodeIdentifier (get_variable_cname (last_param.name))); + int nParams = ccode.get_parameter_count (); + if (nParams == 0 || !ccode.get_parameter (nParams - 1).ellipsis) { + Report.error (expr.source_reference, "`va_list' used in method with fixed args"); + } else if (nParams == 1) { + Report.error (expr.source_reference, "`va_list' used in method without parameter"); + } else { + creation_call.add_argument (new CCodeIdentifier (ccode.get_parameter (nParams - 2).name)); + } } } }