summaryrefslogtreecommitdiff
path: root/noncore/apps
authorerik <erik>2007-01-24 19:54:07 (UTC)
committer erik <erik>2007-01-24 19:54:07 (UTC)
commit89e81059e832ff77c2f0ac8b9db12f80eafa03fc (patch) (side-by-side diff)
tree99a130fc643d2aeefdecab452f644e7b61a5f50e /noncore/apps
parent035bbc5bf689839c8d8e7be37f347b0dd900fccf (diff)
downloadopie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.zip
opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.gz
opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.bz2
Each file in this commit has an instance where a pointer is checked at
one point in the code and then not checked in another point in the code. If it needed to be checked once, it needs to be checked the other time. If not the application could segfault.
Diffstat (limited to 'noncore/apps') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/checkbook/mainwindow.cpp3
-rw-r--r--noncore/apps/opie-console/procctl.cpp3
-rw-r--r--noncore/apps/tinykate/libkate/document/katedocument.cpp63
3 files changed, 36 insertions, 33 deletions
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp
index d9e2047..8e2e2e3 100644
--- a/noncore/apps/checkbook/mainwindow.cpp
+++ b/noncore/apps/checkbook/mainwindow.cpp
@@ -198,134 +198,133 @@ void MainWindow::addCheckbook( CBInfo *cb )
QString balance;
balance.sprintf( "%.2f", cb->balance() );
balance.prepend( _cfg.getCurrencySymbol() );
lvi->setText( posName + 1, balance );
}
}
void MainWindow::buildFilename( const QString &name )
{
tempFilename = cbDir;
tempFilename.append( name );
tempFilename.append( ".qcb" );
}
void MainWindow::slotNew()
{
CBInfo *cb = new CBInfo();
Checkbook *currcb = new Checkbook( this, cb, &_cfg );
if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted )
{
// Save new checkbook
buildFilename( cb->name() );
_cfg.setLastBook( cb->name() );
cb->setFilename( tempFilename );
cb->write();
// Add to listbox
checkbooks->inSort( cb );
addCheckbook( cb );
}
delete currcb;
}
// --- slotEdit ---------------------------------------------------------------
void MainWindow::slotEdit()
{
// get name and open it
QListViewItem *curritem = cbList->currentItem();
if ( !curritem )
return;
openBook( curritem );
}
// --- openBook ---------------------------------------------------------------
void MainWindow::openBook(QListViewItem *curritem)
{
+ if ( !curritem ) return;
// find book in List
QString currname=curritem->text(posName);
CBInfo *cb = checkbooks->first();
while ( cb ) {
if ( cb->name() == currname )
break;
cb = checkbooks->next();
}
if ( !cb ) return;
//
buildFilename( currname );
float currbalance = cb->balance();
bool currlock = !cb->password().isNull();
if ( currlock )
{
Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) );
if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() )
{
delete pw;
return;
}
delete pw;
}
_cfg.setLastBook( currname );
Checkbook *currcb = new Checkbook( this, cb, &_cfg );
if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted )
{
QString newname = cb->name();
if ( currname != newname )
{
// Update name if changed
- if( curritem ) {
curritem->setText( posName, newname );
cbList->sort();
- }
_cfg.setLastBook( newname );
// Remove old file
QFile f( tempFilename );
if ( f.exists() )
f.remove();
// Get new filename
buildFilename( newname );
cb->setFilename( tempFilename );
}
cb->write();
// Update lock if changed
if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock )
{
if ( !cb->password().isNull() )
curritem->setPixmap( 0, lockIcon );
else
curritem->setPixmap( 0, nullIcon );
}
// Update balance if changed
if ( _cfg.getShowBalances() && cb->balance() != currbalance )
{
QString tempstr;
tempstr.sprintf( "%.2f", cb->balance() );
tempstr.prepend( _cfg.getCurrencySymbol() );
curritem->setText( posName + 1, tempstr );
}
// write config, if needed
if( _cfg.isDirty() ) {
Config config("checkbook");
_cfg.writeConfig( config );
}
}
delete currcb;
}
// --- slotDelete -------------------------------------------------------------
void MainWindow::slotDelete()
{
QString currname = cbList->currentItem()->text( posName );
if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) )
{
diff --git a/noncore/apps/opie-console/procctl.cpp b/noncore/apps/opie-console/procctl.cpp
index a44529b..5239e26 100644
--- a/noncore/apps/opie-console/procctl.cpp
+++ b/noncore/apps/opie-console/procctl.cpp
@@ -4,94 +4,97 @@
#include <unistd.h>
#include "procctl.h"
ProcContainer *ProcCtl::m_last = 0;
ProcCtl* ProcCtl::m_self = 0;
ProcCtl::ProcCtl() {
signal( SIGCHLD, signal_handler );
}
ProcCtl::~ProcCtl() {
}
ProcCtl* ProcCtl::self() {
if (!m_self ) {
m_self = new ProcCtl;
}
return m_self;
}
void ProcCtl::add(pid_t pi, int fd ) {
ProcContainer * con = new ProcContainer;
//memset(con, 0, sizeof(con) );
con->pid = pi;
con->fd = fd;
con->status = 0;
con->prev = m_last;
m_last = con;
}
void ProcCtl::remove( pid_t pi ) {
/*
* We first check if the last item
* is equal to pi the we
*
*/
ProcContainer* con;
if (m_last->pid == pi ) {
con = m_last;
m_last = con->prev;
delete con;
return;
}
con = m_last;
ProcContainer* forw = 0l;
while (con ) {
/* remove it */
if ( pi == con->pid ) {
+ if (forw)
forw->prev = con->prev;
+ else
+ forw = con->prev;
delete con;
return;
}
forw = con;
con = con->prev;
}
}
void ProcCtl::remove( ProcContainer con ) {
remove( con.pid );
}
int ProcCtl::status(pid_t pid )const{
ProcContainer *con = m_last;
while (con) {
if (con->pid == pid )
return con->status;
con = con->prev;
}
return -1;
}
void ProcCtl::signal_handler(int) {
int status;
signal( SIGCHLD, signal_handler );
pid_t pi = waitpid( -1, &status, WNOHANG );
/*
* find the container for pid
*
*/
if ( pi < 0 ) {
return;
}
ProcContainer* con = m_last;
while (con) {
if ( con->pid == pi ) {
con->status = status;
char result = 1;
/* give a 'signal' */
::write(con->fd, &result, 1 );
}
con = con->prev;
}
}
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp
index b82a86a..692fd46 100644
--- a/noncore/apps/tinykate/libkate/document/katedocument.cpp
+++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp
@@ -1970,370 +1970,371 @@ void KateDocument::slotBufferChanged() {
//updateLines();//JW
updateViews();
}
void KateDocument::slotBufferHighlight(long start,long stop) {
kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl;
updateLines(start,stop);
// buffer->startLoadTimer();
}
void KateDocument::updateViews(KateView *exclude) {
KateView *view;
int flags;
bool markState = hasMarkedText();
flags = (newDocGeometry) ? KateView::ufDocGeometry : 0;
for (view = views.first(); view != 0L; view = views.next() ) {
if (view != exclude) view->updateView(flags);
// notify every view about the changed mark state....
if (oldMarkState != markState) emit view->newMarkStatus();
}
oldMarkState = markState;
newDocGeometry = false;
}
QColor &KateDocument::cursorCol(int x, int y) {
int attr;
Attribute *a;
TextLine::Ptr textLine = getTextLine(y);
attr = textLine->getRawAttr(x);
a = &m_attribs[attr & taAttrMask];
if (attr & taSelected) return a->selCol; else return a->col;
}
void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs)
{
paintTextLine (paint, line, 0, xStart, xEnd, showTabs);
}
void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs)
{
TextLine::Ptr textLine;
int len;
const QChar *s;
int z, x;
QChar ch;
- Attribute *a = 0L;
+ Attribute *attrptr = 0L;
int attr, nextAttr;
int xs;
int xc, zc;
if (line > lastLine()) {
paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]);
return;
}
textLine = getTextLine(line);
len = textLine->length();
s = textLine->getText();
// skip to first visible character
x = 0;
z = 0;
do {
xc = x;
zc = z;
if (z == len) break;
ch = s[z];//textLine->getChar(z);
if (ch == '\t') {
x += m_tabWidth - (x % m_tabWidth);
} else {
- a = &m_attribs[textLine->getAttr(z)];
+ attrptr = &m_attribs[textLine->getAttr(z)];
- if (a->bold && a->italic)
+ if (attrptr->bold && attrptr->italic)
x += myFontMetricsBI.width(ch);
- else if (a->bold)
+ else if (attrptr->bold)
x += myFontMetricsBold.width(ch);
- else if (a->italic)
+ else if (attrptr->italic)
x += myFontMetricsItalic.width(ch);
else
x += myFontMetrics.width(ch);
}
z++;
} while (x <= xStart);
// draw background
xs = xStart;
attr = textLine->getRawAttr(zc);
while (x < xEnd)
{
nextAttr = textLine->getRawAttr(z);
if ((nextAttr ^ attr) & taSelected)
{
if (attr & taSelected)
paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]);
else
paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]);
xs = x;
attr = nextAttr;
}
if (z == len) break;
ch = s[z];//textLine->getChar(z);
if (ch == '\t')
x += m_tabWidth - (x % m_tabWidth);
else
{
- a = &m_attribs[textLine->getAttr(z)];
+ attrptr = &m_attribs[textLine->getAttr(z)];
- if (a->bold && a->italic)
+ if (attrptr->bold && attrptr->italic)
x += myFontMetricsBI.width(ch);
- else if (a->bold)
+ else if (attrptr->bold)
x += myFontMetricsBold.width(ch);
- else if (a->italic)
+ else if (attrptr->italic)
x += myFontMetricsItalic.width(ch);
else
x += myFontMetrics.width(ch);
}
z++;
}
if (attr & taSelected)
paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]);
else
paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]);
len = z; //reduce length to visible length
// draw text
x = xc;
z = zc;
y += fontAscent;// -1;
attr = -1;
while (z < len) {
ch = s[z];//textLine->getChar(z);
if (ch == '\t') {
if (z > zc) {
//this should cause no copy at all
QConstString str((QChar *) &s[zc], z - zc /*+1*/);
QString s = str.string();
paint.drawText(x - xStart, y, s);
- if (a->bold && a->italic)
+ if (attrptr && attrptr->bold && attrptr->italic)
x += myFontMetricsBI.width(s);
- else if (a->bold)
+ else if (attrptr && attrptr->bold)
x += myFontMetricsBold.width(s);
- else if (a->italic)
+ else if (attrptr && attrptr->italic)
x += myFontMetricsItalic.width(s);
else
x += myFontMetrics.width(s);
}
zc = z +1;
if (showTabs) {
nextAttr = textLine->getRawAttr(z);
if (nextAttr != attr) {
attr = nextAttr;
- a = &m_attribs[attr & taAttrMask];
+ attrptr = &m_attribs[attr & taAttrMask];
- if (attr & taSelected) paint.setPen(a->selCol);
- else paint.setPen(a->col);
+ if (attr & taSelected) paint.setPen(attrptr->selCol);
+ else paint.setPen(attrptr->col);
- if (a->bold && a->italic)
+ if (attrptr->bold && attrptr->italic)
paint.setFont(myFontBI);
- else if (a->bold)
+ else if (attrptr->bold)
paint.setFont(myFontBold);
- else if (a->italic)
+ else if (attrptr->italic)
paint.setFont(myFontItalic);
else
paint.setFont(myFont);
}
-// paint.drawLine(x - xStart, y -2, x - xStart, y);
-// paint.drawLine(x - xStart, y, x - xStart + 2, y);
paint.drawPoint(x - xStart, y);
paint.drawPoint(x - xStart +1, y);
paint.drawPoint(x - xStart, y -1);
}
x += m_tabWidth - (x % m_tabWidth);
} else {
nextAttr = textLine->getRawAttr(z);
if (nextAttr != attr) {
if (z > zc) {
QConstString str((QChar *) &s[zc], z - zc /*+1*/);
QString s = str.string();
paint.drawText(x - xStart, y, s);
- if (a->bold && a->italic)
+ if (attrptr->bold && attrptr->italic)
x += myFontMetricsBI.width(s);
- else if (a->bold)
+ else if (attrptr->bold)
x += myFontMetricsBold.width(s);
- else if (a->italic)
+ else if (attrptr->italic)
x += myFontMetricsItalic.width(s);
else
x += myFontMetrics.width(s);
zc = z;
}
attr = nextAttr;
- a = &m_attribs[attr & taAttrMask];
+ attrptr = &m_attribs[attr & taAttrMask];
- if (attr & taSelected) paint.setPen(a->selCol);
- else paint.setPen(a->col);
+ if (attr & taSelected) paint.setPen(attrptr->selCol);
+ else paint.setPen(attrptr->col);
- if (a->bold && a->italic)
+ if (attrptr->bold && attrptr->italic)
paint.setFont(myFontBI);
- else if (a->bold)
+ else if (attrptr->bold)
paint.setFont(myFontBold);
- else if (a->italic)
+ else if (attrptr->italic)
paint.setFont(myFontItalic);
else
paint.setFont(myFont);
}
}
z++;
}
if (z > zc) {
QConstString str((QChar *) &s[zc], z - zc /*+1*/);
paint.drawText(x - xStart, y, str.string());
}
}
// Applies the search context, and returns whether a match was found. If one is,
// the length of the string matched is also returned.
bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) {
int line, col;
int searchEnd;
int bufLen, tlen;
QChar *t;
TextLine::Ptr textLine;
int pos, newPos;
if (searchFor.isEmpty()) return false;
bufLen = 0;
t = 0L;
line = sc.cursor.y;
col = sc.cursor.x;
if (!(sc.flags & KateView::sfBackward)) {
//forward search
if (sc.flags & KateView::sfSelected) {
if (line < selectStart) {
line = selectStart;
col = 0;
}
searchEnd = selectEnd;
} else searchEnd = lastLine();
while (line <= searchEnd) {
textLine = getTextLine(line);
tlen = textLine->length();
if (tlen > bufLen) {
delete [] t;
bufLen = (tlen + 255) & (~255);
t = new QChar[bufLen];
- }
+ } else if (!t)
+ t = new QChar[bufLen];
+
memcpy(t, textLine->getText(), tlen*sizeof(QChar));
if (sc.flags & KateView::sfSelected) {
pos = 0;
do {
pos = textLine->findSelected(pos);
newPos = textLine->findUnselected(pos);
memset(&t[pos], 0, (newPos - pos)*sizeof(QChar));
pos = newPos;
} while (pos < tlen);
}
QString text(t, tlen);
if (sc.flags & KateView::sfWholeWords) {
// Until the end of the line...
while (col < tlen) {
// ...find the next match.
col = sc.search(text, col);
if (col != -1) {
// Is the match delimited correctly?
if (((col == 0) || (!m_highlight->isInWord(t[col]))) &&
((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) {
goto found;
}
else {
// Start again from the next character.
col++;
}
}
else {
// No match.
break;
}
}
}
else {
// Non-whole-word search.
col = sc.search(text, col);
if (col != -1)
goto found;
}
col = 0;
line++;
}
} else {
// backward search
if (sc.flags & KateView::sfSelected) {
if (line > selectEnd) {
line = selectEnd;
col = -1;
}
searchEnd = selectStart;
} else searchEnd = 0;
while (line >= searchEnd) {
textLine = getTextLine(line);
tlen = textLine->length();
if (tlen > bufLen) {
delete [] t;
bufLen = (tlen + 255) & (~255);
t = new QChar[bufLen];
- }
+ } else if (!t)
+ t = new QChar[bufLen];
memcpy(t, textLine->getText(), tlen*sizeof(QChar));
if (sc.flags & KateView::sfSelected) {
pos = 0;
do {
pos = textLine->findSelected(pos);
newPos = textLine->findUnselected(pos);
memset(&t[pos], 0, (newPos - pos)*sizeof(QChar));
pos = newPos;
} while (pos < tlen);
}
if (col < 0 || col > tlen) col = tlen;
QString text(t, tlen);
if (sc.flags & KateView::sfWholeWords) {
// Until the beginning of the line...
while (col >= 0) {
// ...find the next match.
col = sc.search(text, col);
if (col != -1) {
// Is the match delimited correctly?
if (((col == 0) || (!m_highlight->isInWord(t[col]))) &&
((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) {
goto found;
}
else {
// Start again from the previous character.
col--;
}
}
else {
// No match.
break;
}
}
}
else {
// Non-whole-word search.
col = sc.search(text, col);
if (col != -1)
goto found;
}
col = -1;
line--;
}
}
sc.flags |= KateView::sfWrapped;
return false;