From: hama Date: Sun, 18 Jan 2015 23:02:00 +0000 (+0100) Subject: Length size problems in ReDirTools X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=0c44550a36e9cff446bf906455ef71d8cdc213ab;p=crepublib Length size problems in ReDirTools --- diff --git a/base/ReHashList.cpp b/base/ReHashList.cpp index afc6420..cc0e6b8 100644 --- a/base/ReHashList.cpp +++ b/base/ReHashList.cpp @@ -144,6 +144,10 @@ void ReHashList::put(const Byte* key, size_t keyLength, const Byte* value, size_t valueLength){ ReSeqArray::Index index; ReSeqArray::Tag tag; + if (keyLength == (size_t) -1) + keyLength = strlen(key); + if (valueLength == (size_t) -1) + valueLength = strlen(value); if (m_keys.binarySearch(key, keyLength, index, &tag)){ // replace the value: m_values.set((ReSeqArray::Index) tag, value, valueLength, 0); diff --git a/base/ReProgramArgs.cpp b/base/ReProgramArgs.cpp index 7bf6cee..9329dee 100644 --- a/base/ReProgramArgs.cpp +++ b/base/ReProgramArgs.cpp @@ -46,12 +46,13 @@ ReProgramArgs::ReProgramArgs(const char* usageList[], const char* examples[]) : m_usage(), m_examples(), - m_properties(), + m_properties(false, 2, 2, 1), m_values(), m_args(NULL), m_argCount(0), m_lastError() { + m_properties.setCapacity(64, 64*8, 64*1024); for (const char** argv = usageList; *argv != NULL; argv++){ m_usage.add(-1, *argv, -1); } @@ -214,7 +215,7 @@ void ReProgramArgs::addString(const char* name, const char* description, * @throws ReOptionException Unknown name or wrong type. */ bool ReProgramArgs::getBool(const char* name) { - ReStringList properties; + ReStringList properties(512, 1024, 2, 2); ReByteBuffer buffer; ReVarArgs args; if (! m_properties.get(name, -1, buffer)) @@ -239,7 +240,7 @@ bool ReProgramArgs::getBool(const char* name) { * @throws ReOptionException Unknown name or wrong type. */ int ReProgramArgs::getInt(const char* name) { - ReStringList properties; + ReStringList properties(512, 1024, 2, 2); ReByteBuffer buffer; ReVarArgs args; if (! m_properties.get(name, -1, buffer)) @@ -264,9 +265,9 @@ int ReProgramArgs::getInt(const char* name) { * @throws ReOptionException Unknown name or wrong type. */ const char* ReProgramArgs::getString(const char* name, ReByteBuffer& buffer) { - ReStringList properties; + ReStringList properties(512, 1024, 2, 2); ReVarArgs args; - if (! m_properties.get(name, -1, buffer)) + if (! m_properties.get(name, strlen(name), buffer)) throw ReOptionException(this, i18n("$1 is not an option name"), name); properties.split(buffer.str(), '\1'); @@ -395,7 +396,7 @@ void ReProgramArgs::setValue(const char* name, const char* value, const char* da */ bool ReProgramArgs::analyseShort(const char* opt, const char* nextArg){ bool rc = false; - ReStringList properties; + ReStringList properties(512, 1024, 2, 2); bool again; ReByteBuffer name; do { @@ -455,7 +456,7 @@ bool ReProgramArgs::analyseShort(const char* opt, const char* nextArg){ * */ void ReProgramArgs::analyseLong(const char* opt){ - ReStringList properties; + ReStringList properties(512, 1024, 2, 2); ReByteBuffer name; search('\0', opt, name, properties); @@ -555,7 +556,7 @@ void ReProgramArgs::help(const char* message, bool issueLastError, ReByteBuffer param; while(m_properties.next(position, &name, &prop)){ - ReStringList properties; + ReStringList properties(512, 1024, 2, 2); properties.split(prop.str(), '\1'); line.setLength(0); DataType dataType = DataType(properties.strOf(IxType)[0]); @@ -610,7 +611,7 @@ void ReProgramArgs::help(const char* message, bool issueLastError, } void ReProgramArgs::help(const char* message, bool issueLastError, FILE* stream) const{ - ReStringList lines; + ReStringList lines(512, 1024, 2, 2); help(message, issueLastError, lines); for(size_t ii = 0; ii < lines.count(); ii++){ fputs(lines.strOf(ii), stream); diff --git a/base/ReSeqArray.cpp b/base/ReSeqArray.cpp index ebd8fa0..5fc6c66 100644 --- a/base/ReSeqArray.cpp +++ b/base/ReSeqArray.cpp @@ -11,6 +11,16 @@ enum RELOC_SEQARRAY { LC_SET_SIZES_1 = LC_SEQARRAY + 1, // 50201 LC_SET_SIZES_2, // 50202 LC_SET_SIZES_3, // 50203 + LC_SET_SEQ_1, // 50204 + LC_SET_SEQ_2, // 50205 + LC_SET_SEQ_3, // 50206 + LC_SET_SEQ_4, // 50207 + LC_SET_SEQ_5, // 50208 + LC_SET_SEQ_6, // 50209 + LC_SET_SEQ_7, // 50210 + LC_SET_SEQ_8, // 50211 + LC_SET_SEQ_9, // 50212 + LC_SET_SEQ_10, // 50213 }; /** * @file @@ -484,24 +494,39 @@ void ReSeqArray::setSequence(Sequence* seq, Index index, size_t length, Tag tag) uint8_t* ptr = reinterpret_cast(seq) + m_offsetOfLength; switch (m_sizeOfLength){ case 1: + if (length > 0xff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_1, + i18n("length > 255: $1")).arg((int64_t) length).end(); ptr[0] = length & 0xff; break; case 2: + if (length > 0xffff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_2, + i18n("length > 64k: $1")).arg((int64_t) length).end(); ptr[0] = length & 0xff; ptr[1] = (length >> 8) & 0xff; break; case 3: + if (length > 0xffffff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_3, + i18n("length > 16M: $1")).arg((int64_t) length).end(); ptr[0] = length & 0xff; ptr[1] = (length >> 8) & 0xff; ptr[2] = (length >> 16) & 0xff; break; case 4: + if (length > 0xffffffff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_4, + i18n("length > 4G: $1")).arg((int64_t) length).end(); ptr[0] = length & 0xff; ptr[1] = (length >> 8) & 0xff; ptr[2] = (length >> 16) & 0xff; ptr[3] = (length >> 24) & 0xff; break; case 5: + if (length > 0xffffffff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_5, + i18n("length > 1T: $1")).arg((int64_t) length).end(); ptr[0] = length & 0xff; ptr[1] = (length >> 8) & 0xff; ptr[2] = (length >> 16) & 0xff; @@ -517,24 +542,39 @@ void ReSeqArray::setSequence(Sequence* seq, Index index, size_t length, Tag tag) uint8_t* ptr = reinterpret_cast(seq) + m_offsetOfTag; switch (m_sizeOfTag){ case 1: + if (tag > 0xff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_6, + i18n("tag > 255: $1")).arg((int64_t) tag).end(); ptr[0] = tag & 0xff; break; case 2: - ptr[0] = length & 0xff; + if (tag > 0xffff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_7, + i18n("tag > 64k: $1")).arg((int64_t) tag).end(); + ptr[0] = tag & 0xff; ptr[1] = (tag >> 8) & 0xff; break; case 3: + if (tag > 0xffffff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_8, + i18n("tag > 16M: $1")).arg((int64_t) tag).end(); ptr[0] = tag & 0xff; ptr[1] = (tag >> 8) & 0xff; ptr[2] = (tag >> 16) & 0xff; break; case 4: + if (tag > 0xffffffff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_9, + i18n("tag > 4G: $1")).arg((int64_t) tag).end(); ptr[0] = tag & 0xff; ptr[1] = (tag >> 8) & 0xff; ptr[2] = (tag >> 16) & 0xff; ptr[3] = (tag >> 24) & 0xff; break; case 5: + if (tag > 0xffffffff) + globalLogger()->sayF(LOG_ERROR | CAT_LIB, LC_SET_SEQ_10, + i18n("tag > 1T: $1")).arg((int64_t) tag).end(); ptr[0] = tag & 0xff; ptr[1] = (tag >> 8) & 0xff; ptr[2] = (tag >> 16) & 0xff; diff --git a/base/ReStringList.cpp b/base/ReStringList.cpp index 2acae52..f0bf879 100644 --- a/base/ReStringList.cpp +++ b/base/ReStringList.cpp @@ -12,9 +12,11 @@ * @param deltaList list reservation will be incremented by this amount * @param deltaBuffer buffer reservation will be incremented by this amount */ -ReStringList::ReStringList(int deltaList, int deltaBuffer) : +ReStringList::ReStringList(int deltaList, int deltaBuffer, int sizeOfTag, + int sizeOfLength, size_t constantLength) : ReSeqArray(deltaList, deltaBuffer) { + setSizes(sizeOfTag, sizeOfLength, constantLength); } /** @brief Destructor. diff --git a/base/ReStringList.hpp b/base/ReStringList.hpp index df96e71..7f5efa8 100644 --- a/base/ReStringList.hpp +++ b/base/ReStringList.hpp @@ -31,7 +31,8 @@ */ class ReStringList : public ReSeqArray { public: - ReStringList(int deltaList = 1024, int deltaBuffer = 1024); + ReStringList(int deltaList = 1024, int deltaBuffer = 1024, int sizeOfTag = 4, + int sizeOfLength = 1, size_t constantLength = INDIVIDUAL_SIZE); virtual ~ReStringList(); public: ReStringList& append(const char* source, Tag tag = 0); diff --git a/cunit/testall.cpp b/cunit/testall.cpp index 961541a..246b62f 100644 --- a/cunit/testall.cpp +++ b/cunit/testall.cpp @@ -55,7 +55,7 @@ void testString(){ } void testOs(){ void testReTraverser(); - //testReTraverser(); + testReTraverser(); } void testMath(){ extern void testReRandomizer(); @@ -64,9 +64,9 @@ void testMath(){ void testAll(){ try { + testOs(); testBase(); testMath(); - testOs(); testString(); } catch (ReException e){ fprintf(stderr, "testBase.cpp: unexpected exception: %s\n", e.getMessage()); diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 4c0269c..b0d09dc 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -171,6 +171,8 @@ void ReDirOptions::addStandardFilterOptions(){ "units: m(inutes) h(hours), d(days). Default: m(inutes)\n" "examples: -o25 --older-than=30d -o24h -o2009.3.2/12:00 -o1999.01.01"), 'o', "older-than", false, NULL); +ReByteBuffer buffer; +const char* ptr = m_programArgs.getString("older", buffer); m_programArgs.addString("pathpattern", i18n("a list of patterns for the path (without basename)\n" "the separator is the first character of the list\n" @@ -180,7 +182,8 @@ void ReDirOptions::addStandardFilterOptions(){ "and none of the 'not patterns' matches\n" "examples: ';*;-*/.git/' ',*/cache/,*/temp/"), 'P', "path-pattern", false, NULL); - m_programArgs.addString("nodepattern", +ptr = m_programArgs.getString("older", buffer); + m_programArgs.addString("nodepattern", i18n("a list of patterns for the basename (name without path) separated by ';'\n" "Each pattern can contain '*' as wildcard\n" "If the first character is '-' the pattern is a 'not pattern':\n" @@ -188,14 +191,17 @@ void ReDirOptions::addStandardFilterOptions(){ "of the 'not patterns' matches\n" "examples: '*.cpp;*.hpp;Make*' '*;-*.bak;-*~"), 'p', "basename-pattern", false, NULL); - m_programArgs.addBool("quiet", +ptr = m_programArgs.getString("older", buffer); + m_programArgs.addBool("quiet", i18n("no additional information like runtime"), 'q', "quiet", false); - m_programArgs.addInt("trace", +ptr = m_programArgs.getString("older", buffer); + m_programArgs.addInt("trace", i18n("all seconds the current path will be traced\n" "0: no trace"), 'T', "trace-interval", 0); - m_programArgs.addString("type", +ptr = m_programArgs.getString("older", buffer); + m_programArgs.addString("type", i18n("the file type\n" " is a list of values:\n" ": b(lock) c(har) d(irectory) (l)i(nkdir) l(ink) o(ther)\n" @@ -203,23 +209,27 @@ void ReDirOptions::addStandardFilterOptions(){ "-sets: S(pecial)=bcspo N(ondir)=Slr\n" "examples: -td --type=dr -tNi"), 't', "type", false, NULL); - m_programArgs.addString("younger", +ptr = m_programArgs.getString("older", buffer); + m_programArgs.addString("younger", i18n("the modification date is younger than \n" " is a date (e.g. 2015.02.17) or number followed by an unit\n" "units: m(inutes) h(hours), d(days). Default: m(inutes)"), 'y', "younger-than", false, NULL); - m_programArgs.addString("maxsize", +ptr = m_programArgs.getString("older", buffer); + m_programArgs.addString("maxsize", i18n("the filesize is greater or equal \n" " is a number followed by an unit\n" "units: b(yte) k(Byte) K(iByte) m(Byte), M(iByte), g(Byte) G(iByte)\n" "examples: -Z50m --max-size=1G"), 'Z', "max-size", false, NULL); - m_programArgs.addString("minsize", +ptr = m_programArgs.getString("older", buffer); + m_programArgs.addString("minsize", i18n("the filesize is greater or equal \n" " is a number followed by an unit\n" "units: b(yte) k(Byte) K(iByte) m(Byte), M(iByte), g(Byte) G(iByte)\n" "examples: -z50m --min-size=1G"), 'z', "min-size", false, NULL); +ptr = m_programArgs.getString("older", buffer); } /**