summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
authorzecke <zecke>2003-02-22 16:33:34 (UTC)
committer zecke <zecke>2003-02-22 16:33:34 (UTC)
commit2424bcd292444b3a03c9b92dbc7f5b392c355755 (patch) (side-by-side diff)
tree7f909f39bce8ba8501d07dc6ff238ae7918fc8de /libopie2/opiepim
parent66b00525256255290dfcd9d48ebe1539f15b8dce (diff)
downloadopie-2424bcd292444b3a03c9b92dbc7f5b392c355755.zip
opie-2424bcd292444b3a03c9b92dbc7f5b392c355755.tar.gz
opie-2424bcd292444b3a03c9b92dbc7f5b392c355755.tar.bz2
fixx off by one in reading
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp29
-rw-r--r--libopie2/opiepim/backend/otodoaccessxml.cpp30
2 files changed, 57 insertions, 2 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
index bc51996..24b69fe 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_xml.cpp
@@ -14,24 +14,51 @@
#include <qfile.h>
#include <qtopia/global.h>
#include <qtopia/stringutil.h>
#include <qtopia/timeconversion.h>
#include "opimnotifymanager.h"
#include "orecur.h"
#include "otimezone.h"
#include "odatebookaccessbackend_xml.h"
namespace {
+ // FROM TT again
+char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
+{
+ char needleChar;
+ char haystackChar;
+ if (!needle || !haystack || !hLen || !nLen)
+ return 0;
+
+ const char* hsearch = haystack;
+
+ if ((needleChar = *needle++) != 0) {
+ nLen--; //(to make up for needle++)
+ do {
+ do {
+ if ((haystackChar = *hsearch++) == 0)
+ return (0);
+ if (hsearch >= haystack + hLen)
+ return (0);
+ } while (haystackChar != needleChar);
+ } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
+ hsearch--;
+ }
+ return ((char *)hsearch);
+}
+}
+
+namespace {
time_t start, end, created, rp_end;
ORecur* rec;
ORecur* recur() {
if (!rec)
rec = new ORecur;
return rec;
}
int alarmTime;
int snd;
enum Attribute{
FDescription = 0,
@@ -333,25 +360,25 @@ bool ODateBookAccessBackend_XML::loadFile() {
dict.insert( "recparent", new int(FRecParent) );
dict.insert( "recchildren", new int(FRecChildren) );
dict.insert( "exceptions", new int(FExceptions) );
dict.insert( "timezone", new int(FTimeZone) );
char* dt = (char*)map_addr;
int len = attribute.st_size;
int i = 0;
char* point;
const char* collectionString = "<event ";
int strLen = ::strlen(collectionString);
int *find;
- while ( dt + 1 != 0 && (( point = ::strstr( dt+i, collectionString ) ) != 0 ) ) {
+ while ( ( point = ::strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0 ) {
i = point -dt;
i+= strLen;
alarmTime = -1;
snd = 0; // silent
OEvent ev;
rec = 0;
while ( TRUE ) {
while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
++i;
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp
index 22b2469..cda300b 100644
--- a/libopie2/opiepim/backend/otodoaccessxml.cpp
+++ b/libopie2/opiepim/backend/otodoaccessxml.cpp
@@ -8,24 +8,52 @@
#include <unistd.h>
#include <qfile.h>
#include <qvector.h>
#include <qpe/global.h>
#include <qpe/stringutil.h>
#include <qpe/timeconversion.h>
#include "otodoaccessxml.h"
+namespace {
+ // FROM TT again
+char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
+{
+ char needleChar;
+ char haystackChar;
+ if (!needle || !haystack || !hLen || !nLen)
+ return 0;
+
+ const char* hsearch = haystack;
+
+ if ((needleChar = *needle++) != 0) {
+ nLen--; //(to make up for needle++)
+ do {
+ do {
+ if ((haystackChar = *hsearch++) == 0)
+ return (0);
+ if (hsearch >= haystack + hLen)
+ return (0);
+ } while (haystackChar != needleChar);
+ } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
+ hsearch--;
+ }
+ return ((char *)hsearch);
+}
+}
+
+
OTodoAccessXML::OTodoAccessXML( const QString& appName,
const QString& fileName )
: OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
{
if (!fileName.isEmpty() )
m_file = fileName;
else
m_file = Global::applicationFileName( "todolist", "todolist.xml" );
}
OTodoAccessXML::~OTodoAccessXML() {
}
@@ -76,25 +104,25 @@ bool OTodoAccessXML::load() {
}
/* advise the kernel who we want to read it */
::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
/* we do not the file any more */
::close( fd );
char* dt = (char*)map_addr;
int len = attribut.st_size;
int i = 0;
char *point;
const char* collectionString = "<Task ";
int strLen = strlen(collectionString);
- while ( dt+i != 0 && ( point = strstr( dt+i, collectionString ) ) != 0l ) {
+ while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) {
i = point -dt;
i+= strLen;
qWarning("Found a start at %d %d", i, (point-dt) );
OTodo ev;
m_year = m_month = m_day = 0;
while ( TRUE ) {
while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
++i;
if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
break;