Bug 295162

Summary: The CSV Importer plugin crashes when changing the field delimiter
Product: [Applications] kmymoney Reporter: Cristian Oneț <onet.cristian>
Component: generalAssignee: KMyMoney Devel Mailing List <kmymoney-devel>
Status: RESOLVED FIXED    
Severity: crash CC: agander93, onet.cristian
Priority: NOR    
Version: git (master)   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Testfile to reproduce the described bug
New crash information added by DrKonqi

Description Cristian Oneț 2012-03-01 17:47:07 UTC
Created attachment 69220 [details]
Testfile to reproduce the described bug

Version:           git master (using KDE 4.7.4) 
OS:                Linux

The CSV Importer plugin crashes when changing between different values of the field delimiter.

Reproducible: Always

Steps to Reproduce:
1. Open the attached file
2. The field delimiter is set to semicolon(;)
3. Change it to comma(,)
4. Change it to semicolon(;)


Actual Results:  
Crash

Expected Results:  
No crash
Comment 1 Cristian Oneț 2012-03-01 17:49:38 UTC
Created attachment 69221 [details]
New crash information added by DrKonqi

kmymoney (4.6.90-14fa9b811c) on KDE Platform 4.7.4 (4.7.4) using Qt 4.7.4

Attaching the backtrace.

-- Backtrace (Reduced):
#11 0x00007f17eae5a695 in QList<QString>::operator[] (this=0x299c4a8, i=-1) at /usr/include/qt4/QtCore/qlist.h:464
#12 0x00007f17eae36676 in CSVDialog::displayLine (this=0x299c380, data=...) at /home/cristi/dezvoltare/kmymoney/kmymoney/plugins/csvimport/csvdialog.cpp:784
#13 0x00007f17eae3605f in CSVDialog::readFile (this=0x299c380, fname=..., skipLines=0) at /home/cristi/dezvoltare/kmymoney/kmymoney/plugins/csvimport/csvdialog.cpp:724
#14 0x00007f17eae3eb4d in CSVDialog::delimiterChanged (this=0x299c380) at /home/cristi/dezvoltare/kmymoney/kmymoney/plugins/csvimport/csvdialog.cpp:1857
#15 0x00007f17eae2c6fc in CSVDialog::qt_metacall (this=0x299c380, _c=QMetaObject::InvokeMetaMethod, _id=7, _a=0x7fff749e0ff0) at /home/cristi/dezvoltare/kmymoney-build/kmymoney/plugins/csvimport/moc_csvdialog.cpp:130
Comment 2 Cristian Oneț 2012-03-01 18:19:27 UTC
Also after the committed review I have to select the file twice to get all columns in the importer.
Comment 3 allan 2012-03-01 22:21:10 UTC
(In reply to comment #0)
> Created an attachment (id=69220) [details]
> Testfile to reproduce the described bug
> 
> Version:           git master (using KDE 4.7.4) 
> OS:                Linux
> 
> The CSV Importer plugin crashes when changing between different values of the
> field delimiter.
> 
> Reproducible: Always
> 
> Steps to Reproduce:
> 1. Open the attached file
> 2. The field delimiter is set to semicolon(;)
> 3. Change it to comma(,)
> 4. Change it to semicolon(;)
> 
> 
> Actual Results:  
> Crash
> 
> Expected Results:  
> No crash

Yes, agreed.  Many apologies.  I concentrated so much on the new functionality that I failed to check elsewhere properly.

The basic problem was that in CSVDialog::displayLine(), I had an if ()..else () structure, testing whether the memo field was to be copied to the payee field, or vice-versa.  Or, that was the intent.  In fact, if the first test failed, the code for the second case was executed without the second test actually being present.  So, this second route was taken even if no copying was required.

Secondly, changing the field delimiter affects the number of columns detected, so changing this needs to reset the maximum column count, plus reset the m_firstRead flag.  I think this was the cause of your second problem.

All looks well now, but I need to do more testing.
Comment 4 allan 2012-03-12 10:59:48 UTC
I've updated the patches and attached them to the reviewboard entry, which I reopened.

The patch and description were accepted but no request for me to commit them appeared.  Neither has a notification appeared on the list, so I don't know if something went wrong, or if I shouldn't have re-opened the entry?
Comment 5 Cristian Oneț 2012-03-12 11:06:54 UTC
Since a fix is involved just go ahead and push it to the repository. Go trough reviewboard only if you need some feedback before committing a fix. Otherwise we'll be happy just to review your commit.
Comment 6 allan 2012-03-12 12:31:39 UTC
Git commit 00e5d2960445eda62faa1a7458aa2a826cb21d03 by Allan Anderson.
Committed on 11/03/2012 at 22:30.
Pushed by allananderson into branch 'master'.

Fix for problem in CSVDialog::processQifLine() when importing a checking file
which contains debit and credit columns rather than an amount column, when both
fields are empty.  This resulted in the previous value being used again.

M  +251  -69   kmymoney/plugins/csvimport/csvdialog.cpp
M  +23   -7    kmymoney/plugins/csvimport/csvdialog.h
M  +2    -4    kmymoney/plugins/csvimport/csvutil.cpp

http://commits.kde.org/kmymoney/00e5d2960445eda62faa1a7458aa2a826cb21d03