pcp
[Top] [All Lists]

pcp-gui patches for QString.toAscii() un-corruption

To: pcp developers <pcp@xxxxxxxxxxx>
Subject: pcp-gui patches for QString.toAscii() un-corruption
From: "Frank Ch. Eigler" <fche@xxxxxxxxxx>
Date: Sun, 7 Apr 2013 15:11:03 -0400
Delivered-to: pcp@xxxxxxxxxxx
User-agent: Mutt/1.4.2.2i
Hi -

I came across a nasty systemic bug in the pcp-gui code today,
and have a proposed patch in my pcpfans.git fche/pcp-gui branch.

commit b6b7de7ce33eded33f18a6d1d89c33a0d373957a
Author: Frank Ch. Eigler <fche@xxxxxxxxxx>
Date:   Sun Apr 7 14:55:23 2013 -0400

    QString toAscii decorruption
    
    A recurrent coding pattern in the code aimed to get C "const char*"
    pointers out of QString objects, with code that looks like this:
    
              (const char*) object.toAscii()
    
    This is wrong on several levels.  In Qt4 and probably earlier,
    toAscii() returns a (temporary) QByteArray object, not a C string.
    Any casting to hide this leads to direct junk, e.g., failure to save
    pmchart view state to requested file names, or with actual readable
    metric names.  We switch to
    
              object.toAscii().constData()
    
    throughout.  This too is imperfect, as the QByteArray object is
    temporary, and will be deallocated at the next statement (;) boundary,
    which makes the const char*'s contain junk again.  So, cases where
    such pointers are stored beyond a statement need to be strdup()'d.


Please also consider merging

commit 9162d8c74e66b330096195ca8ff38d43bd541989
Author: Frank Ch. Eigler <fche@xxxxxxxxxx>
Date:   Sun Apr 7 14:55:04 2013 -0400

    add emacs .dir-local.el for formatting preferences


- FChE

<Prev in Thread] Current Thread [Next in Thread>