[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Re: PATCH: KonqRun::askSave and URLs containing '%'
From:       Maarten ter Huurne <mth () stack ! nl>
Date:       2001-08-25 14:02:04
[Download RAW message or body]

On Saturday 25 August 2001 11:43, David Faure wrote:

> I think it's a bit dangerous to have an untested patch (I mean, other than
> your tests) in a branch that developers don't test, especially if it's not
> the solution we choose for HEAD. We won't find the other problems in
> safeArg, so the patch itself isn't "safe" :)

I agree that one should be careful not to replace a bug with another bug.

How are other changes for 2.2.1 verified?

> However, this bug can happen in many places where we use .arg(), and moving
> the potentially dangerous argument to the last position isn't the best
> solution (in case two arguments could have '%' in them).
> So maybe we should have something like your safeArg in kdelibs-head,
> publically available, and to be used whereever strings can contain '%' (and
> the message has more than just %1). I don't see how to do this with the
> .arg() syntax, so another syntax is indeed needed. Maybe a "..." (va_args
> etc.) solution would be nicer to the developer though, instead of the
> QStringList.

I thought about "...", but the lack of type checking is a major drawback. 
The QStringList solution has some overhead, but at least it is type-safe.

An alternative would be to use overloading to accept different numbers of 
arguments. After all, there are only 9 possiblities. The overloaded methods 
would then call a method with a variable number of parameters. Since the 
overloaded methods are one-liners, they can be inlined for extra performance.

For example:

class ArgString: public QString
{
public:
    QString arg(const QString &arg1) const
    { return argVar(arg1); }
    QString arg(const QString &arg1, const QString &arg2) const
    { return argVar(arg1, arg2); }
    QString arg(const QString &arg1, const QString &arg2,
        const QString &arg3) const
    { return argVar(arg1, arg2, arg2); }
    // etc

private:
    // Actual argument substitution.
    QString argVar(...) const;
};

Bye,
		Maarten

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic