Menu

#26 Null Pointers manipulation

1.0
closed
aliks-os
None
2014-12-23
2014-12-19
Mauro Anjo
No

Hey Alik,

Testing your new version. It is a great feature to control reports at runtime, but there are some bugs all over the code where you assume that MasterHeader and MasterFooter for instance are always present on a page, and you manipulate a possible null pointer and crashes the app.

For instance lines 1193 and 1253 for MasterHeader. You must check for nullpointer always :) Like:

RptBandObject *bandObj = pageList.at(pageReport)->getBand(MasterHeader);
if ((bandObj != NULL) && (bandObj->showInGroup == 0))
    ...

Regards!

Discussion

  • aliks-os

    aliks-os - 2014-12-19

    Yes you are right, corrected

     
  • Mauro Anjo

    Mauro Anjo - 2014-12-22

    Alik,

    I checked the SVN, all over the code when you do getBand() you should not manipulate the pointer directly before checking for null.

    There are lots of possibilities to crash in this version.

    I found two more that caused problems in my reports, on function prcessGroupHeader, at the end of it should be:

    void QtRPT::prcessGroupHeader(QPrinter *printer, int &y, bool draw, int pageReport) {
    
    ...
    
                            //-----------Added codes here. Thanks to puterk
                            if (y + pageList.at(pageReport)->getBand(DataGroupHeader)->height > ph-mb-mt-yPF-yMF)
                                newPage(printer, y, draw);
                            //-----------ends here. Thanks to puterk
    
                            RptBandObject *bandDataGroupFooter = pageList.at(pageReport)->getBand(DataGroupFooter);
                            if (bandDataGroupFooter != NULL) {
                                if (allowPrintPage(draw,curPage)) { //Draw footer of the group
                                    drawBandRow(pageList.at(pageReport)->getBand(DataGroupFooter), y);
                                }
                                y += pageList.at(pageReport)->getBand(DataGroupFooter)->height;
                            }
                        }
                    }
                }
                RptBandObject *bandMasterFooter = pageList.at(pageReport)->getBand(MasterFooter);
                if ((bandMasterFooter != NULL) && (bandMasterFooter->showInGroup == 0))
                    processMFooter(printer,y,draw);
            }
        }
    }
    

    I believe you should go through all getBand() calls and be sure that there is not a possibility of a null pointer.

    Regards!

     
  • Mauro Anjo

    Mauro Anjo - 2014-12-22

    My bad, the code should be:

    void QtRPT::prcessGroupHeader(QPrinter *printer, int &y, bool draw, int pageReport) {
    
    ...
    
                            //-----------Added codes here. Thanks to puterk
                            if (y + pageList.at(pageReport)->getBand(DataGroupHeader)->height > ph-mb-mt-yPF-yMF)
                                newPage(printer, y, draw);
                            //-----------ends here. Thanks to puterk
    
                            RptBandObject *bandDataGroupFooter = pageList.at(pageReport)->getBand(DataGroupFooter);
                            if (bandDataGroupFooter != NULL) {
                                if (allowPrintPage(draw,curPage)) { //Draw footer of the group
                                    drawBandRow(bandDataGroupFooter, y);
                                }
                                y += bandDataGroupFooter->height;
                            }
                        }
                    }
                }
                RptBandObject *bandMasterFooter = pageList.at(pageReport)->getBand(MasterFooter);
                if ((bandMasterFooter != NULL) && (bandMasterFooter->showInGroup == 0))
                    processMFooter(printer,y,draw);
            }
        }
    }
    
     
  • aliks-os

    aliks-os - 2014-12-23

    Added, thankyou

     
  • aliks-os

    aliks-os - 2014-12-23
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB