[Kst] kst_oldview_branch: kdeextragear-2/kst/kst/datasources/planck
[POSSIBLY UNSAFE]
George Staikos
staikos at kde.org
Thu Jun 3 22:41:06 CEST 2004
CVS commit by staikos:
backport piolib fix
M +88 -14 planckobj.cpp 1.16.4.3 [POSSIBLY UNSAFE: printf]
--- kdeextragear-2/kst/kst/datasources/planck/planckobj.cpp #1.16.4.2:1.16.4.3
@@ -20,4 +20,5 @@
#include <kdebug.h>
+#include <math.h>
//#define PIOLIBDEBUG
@@ -25,4 +26,10 @@
#include <HL2_PIOLIB/PIOErr.h>
+#ifdef NAN
+double NOPOINT = NAN;
+#else
+double NOPOINT = 0.0/0.0; // NaN
+#endif
+
using namespace Planck;
@@ -180,9 +187,19 @@ int Object::readObject(const QString& ob
PIOObject *MyObject = 0L;
PIOParseData MyData;
+ /* Specific data description needed to check that sample were written */
+ PIOParseData MyDataFlag;
- long n = PIORead_1(g->objNames[i], const_cast<char*>(""),
+ PIOSTRING ObjName;
+ sprintf(ObjName, "%s/%s", g->_group->HTMLName, g->objNames[i]);
+
+ /* open the group only for reading this object */
+ PIOGroup *MyGroup=NULL;
+
+ long n = PIORead_1(ObjName,
+ const_cast<char*>("Written"),
const_cast<char*>("PIODOUBLE"),
- const_cast<char*>(range.latin1()), &(g->_group),
- &MyObject, &MyData, 0L);
+ const_cast<char*>(range.latin1()),
+ &MyGroup, &MyObject, &MyData, &MyDataFlag);
+
#ifdef PIOLIBDEBUG
kdDebug() << "READ " << n << " doubles." << endl;
@@ -195,11 +212,30 @@ int Object::readObject(const QString& ob
}
- PIORead_2(buf, 0L, 0L, g->objNames[i], const_cast<char*>("PIODOUBLE"),
+ {
+ /* table to store the sample validity */
+ PIOFLAG *Mask = (PIOFLAG*)_PIOMALLOC(n);
+
+ PIORead_2(buf, 0L, Mask,
+ ObjName,
+ const_cast<char*>("PIODOUBLE"),
const_cast<char*>(range.latin1()),
- const_cast<char*>(""), g->_group, &MyObject, &MyData, 0L,
+ const_cast<char*>("Written"),
+ MyGroup,
+ &MyObject,
+ &MyData,
+ &MyDataFlag,
PIOLONG(n));
+ /* the group is close no need to deletelink */
//PIODeleteLink(buf, g->_group);
+ for (i = 0; i < n; i++) {
+ if (Mask[i] == 0) {
+ buf[i] = NOPOINT;
+ }
+ }
+
+ _PIOFREE(Mask);
+ }
#ifdef PIOLIBDEBUG
kdDebug() << "Read " << n << " samples of data. Range = [" << range << "]" << endl;
@@ -299,7 +336,42 @@ bool ObjectGroup::updateObjectList() {
kdDebug() << " -> objects: " << e << endl;
#endif
+ /* there are two solution:
+ - get directly only the group maximal size,
+ - get the object size (it depend how KST manage index after. */
+#if 1
+ PIOLONG LastIdx,FirstIdx;
+
+ PIOGetGrpSize(&FirstIdx,&LastIdx,_group);
+
for (int i = 0; i < e; ++i) {
- firstIndex[i] = PIOGetBeginObjectIdx(objNames[i], _group);
- lastIndex[i] = PIOGetEndObjectIdx(objNames[i], _group);
+ firstIndex[i] = FirstIdx;
+ lastIndex[i] = LastIdx;
+ }
+#else
+ for (int i = 0; i < e; ++i) {
+ PIOSTRING ObjName;
+
+ /* compute the complete name of an object */
+ /* Problem : if Objectname is bigger than 128 characters TODO */
+ sprintf(ObjName, "%s/%s", _group->HTMLName,objNames[i]);
+ firstIndex[i] = PIOGetBeginObjectIdx(ObjName, 0L);
+ lastIndex[i] = PIOGetEndObjectIdx(ObjName, 0L);
+ }
+ /* remove different vectorial size and set the bigger */
+ {
+ long max_index = 0;
+ for (int i = 0; i < e; ++i) {
+ if (max_index < lastIndex[i]) {
+ max_index = lastIndex[i];
+ }
+ /* add an index if no data were not written */
+ if (max_index < 1) {
+ max_index = 1;
+ }
+ for (int i = 0; i < e; ++i) {
+ firstIndex[i] = 0;
+ lastIndex[i] = max_index;
+ }
+ }
#ifdef PIOLIBDEBUG
kdDebug() << " -> object: " << objNames[i] << endl;
@@ -307,5 +379,7 @@ bool ObjectGroup::updateObjectList() {
kdDebug() << " -> last index: " << (long) lastIndex[i] << endl;
#endif
- }
+
+#endif
+
return true;
}
More information about the Kst
mailing list