[PATCH] templatelayout.cpp: fix potential issue in preprocessTemplate()

Tomaz Canabrava tcanabrava at kde.org
Mon Feb 29 14:58:24 PST 2016


>From phone.
Why not use a simple regexp for that?
Em 29 de fev de 2016 19:16, "Lubomir I. Ivanov" <neolit123 at gmail.com>
escreveu:

> From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
>
> The function preprocessTemplate(), did not account well
> for indexes in Grantlee variables, such as:
> dive.weight# (where # is the index)
> dive.cylinder#
>
> To solve the issue the list (QList<QPair<QString, QString> >)
> for variables to be replaced is populated will all possible
> indexes:
> 0 - MAX_WEIGHTSYSTEM for weights
> 0 - MAX_CYLINDERS for cylinders
>
> Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
> ---
>
> now slower, but less buggy!
> ---
>  desktop-widgets/templatelayout.cpp | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/desktop-widgets/templatelayout.cpp
> b/desktop-widgets/templatelayout.cpp
> index 34443b9..fd0a44c 100644
> --- a/desktop-widgets/templatelayout.cpp
> +++ b/desktop-widgets/templatelayout.cpp
> @@ -55,18 +55,24 @@ TemplateLayout::~TemplateLayout()
>   */
>  static QString preprocessTemplate(const QString &in)
>  {
> +       int i;
>         QString out = in;
> -
> +       QString iStr;
>         QList<QPair<QString, QString> > list;
> -       list << qMakePair(QString("dive.weight"),
> QString("dive.weights."));
> +
> +       /* populate known variables in a QPair list */
>         list << qMakePair(QString("dive.weights"),
> QString("dive.weightList"));
> -       list << qMakePair(QString("dive.cylinder"),
> QString("dive.cylinders."));
> +       for (i = 0; i < MAX_WEIGHTSYSTEMS; i++)
> +               list << qMakePair(QString("dive.weight%1").arg(i),
> QString("dive.weights.%1").arg(i));
> +
>         list << qMakePair(QString("dive.cylinders"),
> QString("dive.cylinderList"));
> +       for (i = 0; i < MAX_CYLINDERS; i++)
> +               list << qMakePair(QString("dive.cylinder%1").arg(i),
> QString("dive.cylinders.%1").arg(i));
>
>         /* lazy method of variable replacement without regex. the Grantlee
> parser
>          * works with a single or no space next to the variable markers -
>          * e.g. '{{ var }}' */
> -       for (int i = 0; i < list.length(); i++) {
> +       for (i = 0; i < list.length(); i++) {
>                 QPair<QString, QString> p = list.at(i);
>                 out.replace("{{ " + p.first + " }}", "{{ " + p.second + "
> }}");
>                 out.replace("{{" + p.first + "}}", "{{" + p.second + "}}");
> --
> 1.7.11.msysgit.0
>
> _______________________________________________
> subsurface mailing list
> subsurface at subsurface-divelog.org
> http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20160229/4e2fb3aa/attachment.html>


More information about the subsurface mailing list