From 8d69f646fb8193ad22921966a50c2f876349f4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Boull=C3=A9?= Date: Fri, 6 Oct 2023 11:58:41 +0200 Subject: [PATCH] WIP step 2 Correction additionnelles pour MAC - ajout de override - remplacement systematique de tous les sprintf par des snprintf - supression de la methode SecureStrcpy de standard, desormais inutile - ancien usage remplace par snprint Corrction pour Ubuntu, pour la compilation de KWTest - nettoyage de quelques lignes de code pour ne plus avoir d'erreurs --- src/Learning/KWDRRuleLibrary/KWDRMath.cpp | 2 +- src/Learning/KWData/KWCYac.cpp | 2 +- src/Learning/KWData/KWCYac.yac | 2 +- src/Learning/KWData/KWContinuous.cpp | 14 ++-- src/Learning/KWData/KWDate.cpp | 26 ++++---- src/Learning/KWData/KWTime.cpp | 23 ++++--- src/Learning/KWData/KWTimestamp.cpp | 2 +- src/Learning/KWData/KWTimestampTZ.cpp | 4 +- src/Learning/KWTest/CreateLargeFiles.cpp | 4 +- src/Learning/KWTest/SparseStudy.cpp | 21 ++---- src/Learning/KWTest/SparseStudy.h | 9 ++- src/Learning/KWTest/StreamTest.cpp | 5 +- src/Learning/KWTest/SystemDivers.cpp | 2 +- src/Learning/MHHistograms/MHHistogram.h | 2 +- src/Learning/genum/MHEnumHistogramCost.h | 2 +- src/Learning/genum/MHGenumHistogram.cpp | 5 -- src/Learning/genum/MHGenumHistogram.h | 7 +- src/Learning/genum/MHGenumHistogramCosts.h | 2 +- src/Learning/genum/MHKMHistogramCost.h | 2 +- .../sample1/SampleOneLearningProblemView.h | 2 +- .../samples/sample2/CMLearningProblemView.h | 1 - .../samples/sample2/CMModelingSpecView.h | 8 +-- .../samples/sample3/MYLearningProblemView.h | 6 +- src/Norm/base/Longint.cpp | 12 ++-- src/Norm/base/MemoryManager.cpp | 10 +-- src/Norm/base/Portability.cpp | 48 ++++---------- src/Norm/base/Portability.h | 8 +-- src/Norm/base/Standard.cpp | 16 ++--- src/Norm/base/SystemResource.cpp | 66 ++++++++----------- src/Norm/genere/Attribute.h | 24 +++---- src/Norm/samples/sample3/PRWorkerView.h | 2 +- src/Parallel/PLSamples/PEPi.cpp | 6 +- 32 files changed, 152 insertions(+), 193 deletions(-) diff --git a/src/Learning/KWDRRuleLibrary/KWDRMath.cpp b/src/Learning/KWDRRuleLibrary/KWDRMath.cpp index 823a54dda..648318547 100644 --- a/src/Learning/KWDRRuleLibrary/KWDRMath.cpp +++ b/src/Learning/KWDRRuleLibrary/KWDRMath.cpp @@ -98,7 +98,7 @@ Symbol KWDRFormatContinuous::ComputeSymbolResult(const KWObject* kwoObject) cons nLength--; if (cValue < 0) nLength++; - sprintf(sBuffer, "%0*.*f", nLength, nPrecision, (double)cValue); + snprintf(sBuffer, sizeof(sBuffer), "%0*.*f", nLength, nPrecision, (double)cValue); return (Symbol)sBuffer; } } diff --git a/src/Learning/KWData/KWCYac.cpp b/src/Learning/KWData/KWCYac.cpp index 1d3934f9a..d722fea70 100644 --- a/src/Learning/KWData/KWCYac.cpp +++ b/src/Learning/KWData/KWCYac.cpp @@ -3215,7 +3215,7 @@ void yyerrorWithLineCorrection(char const* fmt, int nDeltaLineNumber) nLineNumber = yylineno + nDeltaLineNumber; if (nLineNumber <= 0) nLineNumber = 1; - sprintf(sErrorLine, "Line %d", nLineNumber); + snprintf(sErrorLine, sizeof(sErrorLine), "Line %d", nLineNumber); sLabel = fmt; Global::AddError("Read dictionary file", sErrorLine, sLabel); } diff --git a/src/Learning/KWData/KWCYac.yac b/src/Learning/KWData/KWCYac.yac index d1124c72a..13bd7ddec 100644 --- a/src/Learning/KWData/KWCYac.yac +++ b/src/Learning/KWData/KWCYac.yac @@ -1405,7 +1405,7 @@ void yyerrorWithLineCorrection(char const *fmt, int nDeltaLineNumber) nLineNumber = yylineno+nDeltaLineNumber; if (nLineNumber <= 0) nLineNumber = 1; - sprintf(sErrorLine, "Line %d", nLineNumber); + snprintf(sErrorLine, sErrorLine, "Line %d", nLineNumber); sLabel = fmt; Global::AddError("Read dictionary file", sErrorLine, diff --git a/src/Learning/KWData/KWContinuous.cpp b/src/Learning/KWData/KWContinuous.cpp index a9ed654ea..0819a1919 100644 --- a/src/Learning/KWData/KWContinuous.cpp +++ b/src/Learning/KWData/KWContinuous.cpp @@ -1567,7 +1567,7 @@ const char* const KWContinuous::StandardContinuousToString(Continuous cValue) if (cValue == GetMissingValue()) sBuffer[0] = '\0'; else - sprintf(sBuffer, "%.10g", cValue); + snprintf(sBuffer, BUFFER_LENGTH, "%.10g", cValue); return sBuffer; } @@ -1860,7 +1860,7 @@ void KWContinuous::CompareStringToContinuous(Continuous cValue, boolean bShow) return; // Conversion - sprintf(sValue, "%.15g", cValue); + snprintf(sValue, sizeof(sValue), "%.15g", cValue); dRefValue = StandardStringToContinuous(sValue); dNewValue = StringToContinuous(sValue); @@ -1884,7 +1884,7 @@ const char* const KWContinuous::MaxPrecisionDoubleToString(double dValue) { char* sBuffer = StandardGetBuffer(); - sprintf(sBuffer, "%.15g", dValue); + snprintf(sBuffer, BUFFER_LENGTH, "%.15g", dValue); return sBuffer; } @@ -1939,7 +1939,7 @@ void KWContinuous::TestPerformanceStringToContinuous(int nMaxLowerBaseValue, dou { // Nombre positif avec exposant positif cValue = (cUpperBaseValue + nLowerBaseValue) * dPositivePower10[nExponent]; - sprintf(sValue, "%.15g", cValue); + snprintf(sValue, sizeof(sValue), "%.15g", cValue); if (bRefConversion) StandardStringToContinuous(sValue); if (bNewConversion) @@ -1949,7 +1949,7 @@ void KWContinuous::TestPerformanceStringToContinuous(int nMaxLowerBaseValue, dou // Nombre positif avec exposant negatif cValue = (cUpperBaseValue + nLowerBaseValue) * dNegativePower10[nExponent]; - sprintf(sValue, "%.15g", cValue); + snprintf(sValue, sizeof(sValue), "%.15g", cValue); if (bRefConversion) StandardStringToContinuous(sValue); if (bNewConversion) @@ -1959,7 +1959,7 @@ void KWContinuous::TestPerformanceStringToContinuous(int nMaxLowerBaseValue, dou // Nombre negatif avec exposant positif cValue = -(cUpperBaseValue + nLowerBaseValue) * dPositivePower10[nExponent]; - sprintf(sValue, "%.15g", cValue); + snprintf(sValue, sizeof(sValue), "%.15g", cValue); if (bRefConversion) StandardStringToContinuous(sValue); if (bNewConversion) @@ -1969,7 +1969,7 @@ void KWContinuous::TestPerformanceStringToContinuous(int nMaxLowerBaseValue, dou // Nombre negatif avec exposant negatif cValue = -(cUpperBaseValue + nLowerBaseValue) * dNegativePower10[nExponent]; - sprintf(sValue, "%.15g", cValue); + snprintf(sValue, sizeof(sValue), "%.15g", cValue); if (bRefConversion) StandardStringToContinuous(sValue); if (bNewConversion) diff --git a/src/Learning/KWData/KWDate.cpp b/src/Learning/KWData/KWDate.cpp index 640212430..dc148e299 100644 --- a/src/Learning/KWData/KWDate.cpp +++ b/src/Learning/KWData/KWDate.cpp @@ -227,7 +227,7 @@ const char* const Date::ToString() const if (not Check()) sDate[0] = '\0'; else - sprintf(sDate, "%04d-%02d-%02d", GetYear(), GetMonth(), GetDay()); + snprintf(sDate, BUFFER_LENGTH, "%04d-%02d-%02d", GetYear(), GetMonth(), GetDay()); return sDate; } @@ -320,9 +320,11 @@ const char* const Date::TimeZoneToString(boolean bExtended) const else cSign = '-'; if (bExtended) - sprintf(sTimeZone, "%c%02d:%02d", cSign, GetTimeZoneHour(), GetTimeZoneMinute()); + snprintf(sTimeZone, BUFFER_LENGTH, "%c%02d:%02d", cSign, GetTimeZoneHour(), + GetTimeZoneMinute()); else - sprintf(sTimeZone, "%c%02d%02d", cSign, GetTimeZoneHour(), GetTimeZoneMinute()); + snprintf(sTimeZone, BUFFER_LENGTH, "%c%02d%02d", cSign, GetTimeZoneHour(), + GetTimeZoneMinute()); } } return sTimeZone; @@ -618,11 +620,11 @@ const char* const KWDateFormat::DateToString(Date dtValue) const nOffset = 0; assert(nOffset == nYearOffset or nOffset == nMonthOffset or nOffset == nDayOffset); if (nYearOffset == 0) - nOffset += sprintf(sBuffer, "%04d", dtValue.GetYear()); + nOffset += snprintf(sBuffer, BUFFER_LENGTH, "%04d", dtValue.GetYear()); else if (nMonthOffset == 0) - nOffset += sprintf(sBuffer, "%02d", dtValue.GetMonth()); + nOffset += snprintf(sBuffer, BUFFER_LENGTH, "%02d", dtValue.GetMonth()); else - nOffset += sprintf(sBuffer, "%02d", dtValue.GetDay()); + nOffset += snprintf(sBuffer, BUFFER_LENGTH, "%02d", dtValue.GetDay()); // Ecriture du premier separateur optionnel if (nSeparatorOffset1 == nOffset) @@ -634,11 +636,11 @@ const char* const KWDateFormat::DateToString(Date dtValue) const // Ecriture du deuxieme champ assert(nOffset == nYearOffset or nOffset == nMonthOffset or nOffset == nDayOffset); if (nYearOffset == nOffset) - nOffset += sprintf(sBuffer + nOffset, "%04d", dtValue.GetYear()); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%04d", dtValue.GetYear()); else if (nMonthOffset == nOffset) - nOffset += sprintf(sBuffer + nOffset, "%02d", dtValue.GetMonth()); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%02d", dtValue.GetMonth()); else - nOffset += sprintf(sBuffer + nOffset, "%02d", dtValue.GetDay()); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%02d", dtValue.GetDay()); // Ecriture du deuxiemme separateur optionnel if (nSeparatorOffset2 == nOffset) @@ -650,11 +652,11 @@ const char* const KWDateFormat::DateToString(Date dtValue) const // Ecriture du troisieme champ assert(nOffset == nYearOffset or nOffset == nMonthOffset or nOffset == nDayOffset); if (nYearOffset == nOffset) - nOffset += sprintf(sBuffer + nOffset, "%04d", dtValue.GetYear()); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%04d", dtValue.GetYear()); else if (nMonthOffset == nOffset) - nOffset += sprintf(sBuffer + nOffset, "%02d", dtValue.GetMonth()); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%02d", dtValue.GetMonth()); else - nOffset += sprintf(sBuffer + nOffset, "%02d", dtValue.GetDay()); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%02d", dtValue.GetDay()); } return sBuffer; } diff --git a/src/Learning/KWData/KWTime.cpp b/src/Learning/KWData/KWTime.cpp index e6490bbce..44f44c3c8 100644 --- a/src/Learning/KWData/KWTime.cpp +++ b/src/Learning/KWData/KWTime.cpp @@ -62,12 +62,13 @@ const char* const Time::ToString() const // Cas ou il n'y a pas de fraction de secondes if (nSecondFrac == 0) - sprintf(sTime, "%02d:%02d:%02d", GetHour(), GetMinute(), (int)timeValue.timeFields.nSecond); + snprintf(sTime, BUFFER_LENGTH, "%02d:%02d:%02d", GetHour(), GetMinute(), + (int)timeValue.timeFields.nSecond); // Cas avec fraction de secondes else { - nLength = sprintf(sTime, "%02d:%02d:%02d.%04d", GetHour(), GetMinute(), - (int)timeValue.timeFields.nSecond, nSecondFrac); + nLength = snprintf(sTime, BUFFER_LENGTH, "%02d:%02d:%02d.%04d", GetHour(), GetMinute(), + (int)timeValue.timeFields.nSecond, nSecondFrac); // Supression des zero en fin pour ne garder que la partie utile des decimales de secondes for (i = 0; i < 4; i++) @@ -660,9 +661,9 @@ const char* const KWTimeFormat::TimeToString(Time tmValue) const nOffset = 0; assert(nOffset == nHourOffset); if (bMandatoryFirstDigit) - nOffset += sprintf(sBuffer, "%02d", tmValue.GetHour()); + nOffset += snprintf(sBuffer, BUFFER_LENGTH, "%02d", tmValue.GetHour()); else - nOffset += sprintf(sBuffer, "%d", tmValue.GetHour()); + nOffset += snprintf(sBuffer, BUFFER_LENGTH, "%d", tmValue.GetHour()); // Ecriture du premier separateur optionnel if (nSeparatorOffset1 != -1) @@ -673,9 +674,9 @@ const char* const KWTimeFormat::TimeToString(Time tmValue) const // Ecriture du champ minute if (bMandatoryFirstDigit) - nOffset += sprintf(sBuffer + nOffset, "%02d", tmValue.GetMinute()); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%02d", tmValue.GetMinute()); else - nOffset += sprintf(sBuffer + nOffset, "%d", tmValue.GetMinute()); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%d", tmValue.GetMinute()); // Ecriture du deuxieme separateur optionnel if (nSeparatorOffset2 != -1) @@ -693,9 +694,11 @@ const char* const KWTimeFormat::TimeToString(Time tmValue) const if (nSecondOffset != -1) { if (bMandatoryFirstDigit) - nOffset += sprintf(sBuffer + nOffset, "%02d", (int)floor(tmValue.GetSecond())); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%02d", + (int)floor(tmValue.GetSecond())); else - nOffset += sprintf(sBuffer + nOffset, "%d", (int)floor(tmValue.GetSecond())); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, "%d", + (int)floor(tmValue.GetSecond())); } // Ecriture de la partie decimale des secondes @@ -709,7 +712,7 @@ const char* const KWTimeFormat::TimeToString(Time tmValue) const // Ecriture des fractions de secondes if (nSecondFrac > 0) { - nOffset += sprintf(sBuffer + nOffset, ".%04d", nSecondFrac); + nOffset += snprintf(sBuffer + nOffset, BUFFER_LENGTH - nOffset, ".%04d", nSecondFrac); // Supression des zero en fin pour ne garder que la partie utile des decimales de // secondes diff --git a/src/Learning/KWData/KWTimestamp.cpp b/src/Learning/KWData/KWTimestamp.cpp index 27df33bd8..c126f943f 100644 --- a/src/Learning/KWData/KWTimestamp.cpp +++ b/src/Learning/KWData/KWTimestamp.cpp @@ -120,7 +120,7 @@ const char* const Timestamp::ToString() const if (not Check()) sTimestamp[0] = '\0'; else - sprintf(sTimestamp, "%s %s", GetDate().ToString(), GetTime().ToString()); + snprintf(sTimestamp, BUFFER_LENGTH, "%s %s", GetDate().ToString(), GetTime().ToString()); return sTimestamp; } diff --git a/src/Learning/KWData/KWTimestampTZ.cpp b/src/Learning/KWData/KWTimestampTZ.cpp index 7d2f82022..449f7b68b 100644 --- a/src/Learning/KWData/KWTimestampTZ.cpp +++ b/src/Learning/KWData/KWTimestampTZ.cpp @@ -51,8 +51,8 @@ const char* const TimestampTZ::ToString() const if (not Check()) sTimestampTZ[0] = '\0'; else - sprintf(sTimestampTZ, "%s %s%s", GetInternalDate().ToString(), GetInternalTime().ToString(), - GetInternalDate().TimeZoneToString(true)); + snprintf(sTimestampTZ, BUFFER_LENGTH, "%s %s%s", GetInternalDate().ToString(), + GetInternalTime().ToString(), GetInternalDate().TimeZoneToString(true)); return sTimestampTZ; } diff --git a/src/Learning/KWTest/CreateLargeFiles.cpp b/src/Learning/KWTest/CreateLargeFiles.cpp index 7a3efed0a..ac0df0035 100644 --- a/src/Learning/KWTest/CreateLargeFiles.cpp +++ b/src/Learning/KWTest/CreateLargeFiles.cpp @@ -9,7 +9,7 @@ boolean MovePositionInBinaryFile(FILE* fFile, longint lOffset) boolean bOk; // Pour les fichiers de plus de 4 Go, il existe une API speciale (stat64...) -#if defined __MSC__ +#ifdef _WIN32 _fseeki64(fFile, lOffset, SEEK_CUR); #elif defined(__APPLE__) fseeko(fFile, lOffset, SEEK_CUR); @@ -25,7 +25,7 @@ longint TellPositionInBinaryFile(FILE* fFile) longint lCurrentPosition; // Pour les fichiers de plus de 4 Go, il existe une API speciale (stat64...) -#if defined __MSC__ +#ifdef _WIN32 lCurrentPosition = _ftelli64(fFile); #elif defined(__APPLE__) lCurrentPosition = ftello(fFile); diff --git a/src/Learning/KWTest/SparseStudy.cpp b/src/Learning/KWTest/SparseStudy.cpp index ca460a80f..f143e2166 100644 --- a/src/Learning/KWTest/SparseStudy.cpp +++ b/src/Learning/KWTest/SparseStudy.cpp @@ -252,9 +252,6 @@ void BasicVectorAccessTest() } } -#include -using namespace std::chrono; - void DoubleVectorAccessTest() { const int nSize = 1000; @@ -264,16 +261,14 @@ void DoubleVectorAccessTest() int i; double dTotal; char* dvVectorAdress; - std::chrono::time_point start; - std::chrono::time_point stop; - double dDuration; + Timer timer; // Initialisation for (i = 0; i < nSize; i++) dvVector[i] = i; // Lecture - start = high_resolution_clock::now(); + timer.Start(); dTotal = 0; for (nStep = 0; nStep < nStepNumber; nStep++) { @@ -282,14 +277,13 @@ void DoubleVectorAccessTest() dTotal += dvVector[i]; } } - stop = high_resolution_clock::now(); - dDuration = duration_cast(stop - start).count() / 1000000000.0; + timer.Stop(); cout << "Total: " << dTotal << endl; - cout << "Duration: " << dDuration << endl; + cout << "Duration: " << timer.GetElapsedTime() << endl; // Lecture dvVectorAdress = (char*)(void*)&dvVector; - start = high_resolution_clock::now(); + timer.Start(); dTotal = 0; for (nStep = 0; nStep < nStepNumber; nStep++) { @@ -298,10 +292,9 @@ void DoubleVectorAccessTest() dTotal += *((double*)&dvVectorAdress[i * 8]); } } - stop = high_resolution_clock::now(); - dDuration = duration_cast(stop - start).count() / 1000000000.0; + timer.Stop(); cout << "Total: " << dTotal << endl; - cout << "Duration: " << dDuration << endl; + cout << "Duration: " << timer.GetElapsedTime() << endl; } ///////////////////////////////////////////////////////////////////// diff --git a/src/Learning/KWTest/SparseStudy.h b/src/Learning/KWTest/SparseStudy.h index ae24283be..f33291b70 100644 --- a/src/Learning/KWTest/SparseStudy.h +++ b/src/Learning/KWTest/SparseStudy.h @@ -107,7 +107,7 @@ void DoubleVectorAccessTest(); // Classe KWValueIndexPair // Class technique, utilisee uniquement pour l'implementation des blocs sparse // Pas de "packing" des attribut pour optimiser la place memoire -#ifdef _WIN32 +// #ifdef _WIN32 #pragma pack(push) #pragma pack(1) class KWValueIndexPairTest : public SystemObject @@ -117,6 +117,11 @@ class KWValueIndexPairTest : public SystemObject friend class KWContinuousValueBlockTest; }; #pragma pack(pop) +// Sous linux on doit utiliser __attribute__((packed)); mais pragma pack fonctionne sur clang et gcc, on privilegie donc +// la version portable. ATTENTION il faut declarer nIndex avant value sinon le packing n'est pas fait sur linux (on ne +// sait pas pourquoi) + +/* #else // Linux class KWValueIndexPairTest : public SystemObject { @@ -124,7 +129,7 @@ class KWValueIndexPairTest : public SystemObject int nIndex; friend class KWContinuousValueBlockTest; } __attribute__((packed)); -#endif +#endif*/ ///////////////////////////////////////////////////////////////////// // Classe KWContinuousValueBlock: gestion d'un bloc de valeurs sparse diff --git a/src/Learning/KWTest/StreamTest.cpp b/src/Learning/KWTest/StreamTest.cpp index 17ec1caf5..fcfa11217 100644 --- a/src/Learning/KWTest/StreamTest.cpp +++ b/src/Learning/KWTest/StreamTest.cpp @@ -3,15 +3,16 @@ // at https://spdx.org/licenses/BSD-3-Clause-Clear.html or see the "LICENSE" file for more details. #include "StreamTest.h" + #ifdef _WIN32 #include +#endif // _WIN32 // Visual C++: supression des Warning sur les assignation au sein d'un expression conditionnelle (cf. // TestStreamLineCount7 et TestStreamLineCount8) #ifdef __MSC__ #pragma warning(disable : 4706) // disable C4706 warning -#endif -#endif __MSC__ +#endif // __MSC__ void StreamTest(int argc, char** argv) { diff --git a/src/Learning/KWTest/SystemDivers.cpp b/src/Learning/KWTest/SystemDivers.cpp index 533090b43..37d10deee 100644 --- a/src/Learning/KWTest/SystemDivers.cpp +++ b/src/Learning/KWTest/SystemDivers.cpp @@ -26,7 +26,7 @@ int OpenPdfFile(char* sPdfFilePathName) return ((int)nRet>32); */ char sCommand[1000]; - sprintf(sCommand, "start %s", sPdfFilePathName); + snprintf(sCommand, sizeof(sCommand), "start %s", sPdfFilePathName); system(sCommand); return 0; } diff --git a/src/Learning/MHHistograms/MHHistogram.h b/src/Learning/MHHistograms/MHHistogram.h index 900468369..9b0c11726 100644 --- a/src/Learning/MHHistograms/MHHistogram.h +++ b/src/Learning/MHHistograms/MHHistogram.h @@ -187,7 +187,7 @@ class MHHistogram : public Object virtual void CopyFrom(const MHHistogram* sourceHistogram); // Duplication - virtual MHHistogram* Clone() const; + MHHistogram* Clone() const; // Ecriture sous forme d'un tableau de bins avec leurs caracteristiques virtual void WriteSummary(ostream& ost) const; diff --git a/src/Learning/genum/MHEnumHistogramCost.h b/src/Learning/genum/MHEnumHistogramCost.h index 045697ebc..d68552bcb 100644 --- a/src/Learning/genum/MHEnumHistogramCost.h +++ b/src/Learning/genum/MHEnumHistogramCost.h @@ -33,7 +33,7 @@ class MHEnumHistogramCosts : public MHGenumHistogramCosts double ComputePartCost(const KWFrequencyVector* part) const override; // Calcul du cout global de la partition, definie par le tableau de ses parties - double ComputePartitionGlobalCost(const KWFrequencyTable* partTable) const; + double ComputePartitionGlobalCost(const KWFrequencyTable* partTable) const override; // Affichage du cout de la partition void WritePartitionCost(int nPartNumber, int nGarbageModalityNumber, ostream& ost) const override; diff --git a/src/Learning/genum/MHGenumHistogram.cpp b/src/Learning/genum/MHGenumHistogram.cpp index a1f0b72af..f7301be56 100644 --- a/src/Learning/genum/MHGenumHistogram.cpp +++ b/src/Learning/genum/MHGenumHistogram.cpp @@ -166,11 +166,6 @@ void MHGenumHistogram::CopyFrom(const MHHistogram* sourceHistogram) MHHistogram::CopyFrom(sourceHistogram); } -MHHistogram* MHGenumHistogram::Clone() const -{ - return MHHistogram::Clone(); -} - void MHGenumHistogram::WriteSummary(ostream& ost) const { // Appel de la methode ancetre diff --git a/src/Learning/genum/MHGenumHistogram.h b/src/Learning/genum/MHGenumHistogram.h index 7d0b0db25..cb294c183 100644 --- a/src/Learning/genum/MHGenumHistogram.h +++ b/src/Learning/genum/MHGenumHistogram.h @@ -60,16 +60,13 @@ class MHGenumHistogram : public MHHistogram // Divers // Nettoyage - void Clean(); + void Clean() override; // Creation virtuelle d'un histogramme dans le bon type MHHistogram* Create() const override; // Copie - void CopyFrom(const MHHistogram* sourceHistogram); - - // Duplication - MHHistogram* Clone() const; + void CopyFrom(const MHHistogram* sourceHistogram) override; // Ecriture sous forme d'un tableau de bins avec leurs caracteristiques void WriteSummary(ostream& ost) const override; diff --git a/src/Learning/genum/MHGenumHistogramCosts.h b/src/Learning/genum/MHGenumHistogramCosts.h index 68f196912..d05fa832a 100644 --- a/src/Learning/genum/MHGenumHistogramCosts.h +++ b/src/Learning/genum/MHGenumHistogramCosts.h @@ -41,7 +41,7 @@ class MHGenumHistogramCosts : public KWUnivariatePartitionCosts double ComputePartCost(const KWFrequencyVector* part) const override; // Calcul du cout global de la partition, definie par le tableau de ses parties - double ComputePartitionGlobalCost(const KWFrequencyTable* partTable) const; + double ComputePartitionGlobalCost(const KWFrequencyTable* partTable) const override; // Affichage du cout de la partition void WritePartitionCost(int nPartNumber, int nGarbageModalityNumber, ostream& ost) const override; diff --git a/src/Learning/genum/MHKMHistogramCost.h b/src/Learning/genum/MHKMHistogramCost.h index 4e9d946f5..4d6dcedab 100644 --- a/src/Learning/genum/MHKMHistogramCost.h +++ b/src/Learning/genum/MHKMHistogramCost.h @@ -33,7 +33,7 @@ class MHKMHistogramCosts : public MHGenumHistogramCosts double ComputePartCost(const KWFrequencyVector* part) const override; // Calcul du cout global de la partition, definie par le tableau de ses parties - double ComputePartitionGlobalCost(const KWFrequencyTable* partTable) const; + double ComputePartitionGlobalCost(const KWFrequencyTable* partTable) const override; // Affichage du cout de la partition void WritePartitionCost(int nPartNumber, int nGarbageModalityNumber, ostream& ost) const override; diff --git a/src/Learning/samples/sample1/SampleOneLearningProblemView.h b/src/Learning/samples/sample1/SampleOneLearningProblemView.h index 21bbf3d34..346fb3ff2 100644 --- a/src/Learning/samples/sample1/SampleOneLearningProblemView.h +++ b/src/Learning/samples/sample1/SampleOneLearningProblemView.h @@ -32,6 +32,6 @@ class SampleOneLearningProblemView : public KWLearningProblemView void ExportStats(); // Acces au probleme d'apprentissage - void SetObject(Object* object); + void SetObject(Object* object) override; SampleOneLearningProblem* GetSampleOneLearningProblem(); }; diff --git a/src/Learning/samples/sample2/CMLearningProblemView.h b/src/Learning/samples/sample2/CMLearningProblemView.h index 83dbe1fe3..b6b7e0e0d 100644 --- a/src/Learning/samples/sample2/CMLearningProblemView.h +++ b/src/Learning/samples/sample2/CMLearningProblemView.h @@ -21,7 +21,6 @@ class CMLearningProblemView : public KWLearningProblemView // Rien pour l'instant // Acces au probleme d'apprentissage - // void SetObject(Object* object); CMLearningProblem* GetCMLearningProblem(); }; diff --git a/src/Learning/samples/sample2/CMModelingSpecView.h b/src/Learning/samples/sample2/CMModelingSpecView.h index 41d050d3a..53264d21a 100644 --- a/src/Learning/samples/sample2/CMModelingSpecView.h +++ b/src/Learning/samples/sample2/CMModelingSpecView.h @@ -23,16 +23,16 @@ class CMModelingSpecView : public KWModelingSpecView // Redefinition des methodes a reimplementer obligatoirement /// Mise a jour de l'objet par les valeurs de l'interface - void EventUpdate(Object* object); + void EventUpdate(Object* object) override; /// Mise a jour des valeurs de l'interface par l'objet - void EventRefresh(Object* object); + void EventRefresh(Object* object) override; /// Libelles utilisateur - const ALString GetClassLabel() const; + const ALString GetClassLabel() const override; /// Parametrage de l'objet edite - void SetObject(Object* object); + void SetObject(Object* object) override; //////////////////////////////////////////////////////// //// Implementation diff --git a/src/Learning/samples/sample3/MYLearningProblemView.h b/src/Learning/samples/sample3/MYLearningProblemView.h index 5b973969d..f06b6bda3 100644 --- a/src/Learning/samples/sample3/MYLearningProblemView.h +++ b/src/Learning/samples/sample3/MYLearningProblemView.h @@ -28,7 +28,7 @@ class MYLearningProblemView : public KWLearningProblemView void RegressorBenchmark(); // Acces au probleme d'apprentissage - void SetObject(Object* object); + void SetObject(Object* object) override; MYLearningProblem* GetMyLearningProblem(); }; @@ -48,10 +48,10 @@ class MYLearningProblemExtendedActionView : public UIObjectView // Redefinition des methodes a reimplementer obligatoirement // Mise a jour de l'objet par les valeurs de l'interface - void EventUpdate(Object* object); + void EventUpdate(Object* object) override; // Mise a jour des valeurs de l'interface par l'objet - void EventRefresh(Object* object); + void EventRefresh(Object* object) override; // Actions de menu void ClassifierBenchmark(); diff --git a/src/Norm/base/Longint.cpp b/src/Norm/base/Longint.cpp index 17580db36..b7b172d9d 100644 --- a/src/Norm/base/Longint.cpp +++ b/src/Norm/base/Longint.cpp @@ -25,10 +25,10 @@ const char* const LongintToHumanReadableString(longint lValue) // Affichage exact si des bytes plus petit que 1 KB if (i == 0) - sprintf(sBuffer, "%lld %s", lValue, units[i]); + snprintf(sBuffer, BUFFER_LENGTH, "%lld %s", lValue, units[i]); // Sinon, affichage avec 1 digit de precision else - sprintf(sBuffer, "%.1f %s", lValue / pow(1024.0, i), units[i]); + snprintf(sBuffer, BUFFER_LENGTH, "%.1f %s", lValue / pow(1024.0, i), units[i]); return sBuffer; } @@ -46,7 +46,7 @@ const char* const LongintToReadableString(longint lValue) // Cas des nombre inferieur a 10000 if (lAbsoluteValue < 10000) - sprintf(sBuffer, "%lld", lValue); + snprintf(sBuffer, BUFFER_LENGTH, "%lld", lValue); // Sinon, on insere des separateurs de millier else { @@ -64,14 +64,14 @@ const char* const LongintToReadableString(longint lValue) // Ecriture nPos = 0; if (lValue < 0) - nPos += sprintf(&sBuffer[nPos], "-"); - nPos += sprintf(&sBuffer[nPos], "%d", (int)lTmp); + nPos += snprintf(&sBuffer[nPos], BUFFER_LENGTH - nPos, "-"); + nPos += snprintf(&sBuffer[nPos], BUFFER_LENGTH - nPos, "%d", (int)lTmp); while (lScale > 1) { lScale /= 1000; lTmp = lTmp2 / lScale; lTmp2 = lTmp2 % lScale; - nPos += sprintf(&sBuffer[nPos], ",%03d", (int)lTmp); + nPos += snprintf(&sBuffer[nPos], BUFFER_LENGTH - nPos, ",%03d", (int)lTmp); } } return sBuffer; diff --git a/src/Norm/base/MemoryManager.cpp b/src/Norm/base/MemoryManager.cpp index af4298dce..557d74def 100644 --- a/src/Norm/base/MemoryManager.cpp +++ b/src/Norm/base/MemoryManager.cpp @@ -54,7 +54,8 @@ inline void MemHeapUpdateAlloc(size_t nSize) if (lMemMaxHeapSize > 0 && MemHeapMemory > lMemMaxHeapSize) { char sMessage[100]; - sprintf(sMessage, "Memory user overflow: heap size beyond user limit (%lld)\n", lMemMaxHeapSize); + snprintf(sMessage, sizeof(sMessage), "Memory user overflow: heap size beyond user limit (%lld)\n", + lMemMaxHeapSize); MemFatalError(sMessage); GlobalExit(); } @@ -1528,7 +1529,8 @@ inline void* MemAlloc(size_t nSize) if (MemGetAllocErrorHandler() != NULL) { char sMessage[100]; - sprintf(sMessage, "Memory overflow (malloc allocation error (%lld))\n", (longint)nSize); + snprintf(sMessage, sizeof(sMessage), + "Memory overflow (malloc allocation error (%lld))\n", (longint)nSize); MemFatalError(sMessage); } return NULL; @@ -2028,8 +2030,8 @@ void* DebugMemAlloc(size_t nSize) if (MemGetAllocErrorHandler() != NULL) { char sMessage[100]; - sprintf(sMessage, "Memory overflow (unable to allocate memory (%lld))\n", - (longint)(nSize + MemControlOverhead * sizeof(void*))); + snprintf(sMessage, sizeof(sMessage), "Memory overflow (unable to allocate memory (%lld))\n", + (longint)(nSize + MemControlOverhead * sizeof(void*))); MemFatalError(sMessage); } return NULL; diff --git a/src/Norm/base/Portability.cpp b/src/Norm/base/Portability.cpp index adec8dfa9..53b83fc2b 100644 --- a/src/Norm/base/Portability.cpp +++ b/src/Norm/base/Portability.cpp @@ -143,7 +143,7 @@ void* p_FindFirstFile(const char* dirname, void* pFileData) char sPath[2048]; // On veut tous les fichiers et repertoires - sprintf(sPath, "%s\\*.*", dirname); + snprintf(sPath, sizeof(sPath), "%s\\*.*", dirname); // Recherche la premiere entite du repertoire fdFile = (WIN32_FIND_DATAA*)pFileData; @@ -234,24 +234,6 @@ void StandardGetInputString(char* sBuffer, FILE* fInput) assert(strlen(sBuffer) < BUFFER_LENGTH); } -int SecureStrcpy(char* sDest, const char* sSource, int nMaxLength) -{ - int bOk = 0; - int nLenDest; - int nLengthSource; - - assert(nMaxLength > 0); - - nLengthSource = (int)strlen(sSource); - nLenDest = (int)strlen(sDest); - if (nLenDest + nLengthSource < nMaxLength) - { - strcpy(&sDest[nLenDest], sSource); - bOk = 1; - } - return bOk; -} - // Implementation Windows du lancement d'excutable #ifdef _WIN32 @@ -425,33 +407,26 @@ int OpenApplication(const char* sApplicationExeName, const char* sApplicationLab // Erreur si pas d'association if (!ok) { - sprintf(sErrorMessage, "%s tool not found", sApplicationLabel); + snprintf(sErrorMessage, SYSTEM_MESSAGE_LENGTH, "%s tool not found", sApplicationLabel); } // Lancement de l'application else { // Preparation des arguments: commande de longueur inconnue, et message d'erreur - sCommandLine = new char[strlen(sFileAssociation) + strlen(sFileToOpen) + 10]; - sprintf(sCommandLine, "\"%s\" \"%s\"", sFileAssociation, sFileToOpen); + sCommandLine = StandardGetBuffer(); + snprintf(sCommandLine, BUFFER_LENGTH, "\"%s\" \"%s\"", sFileAssociation, sFileToOpen); + assert(SYSTEM_MESSAGE_LENGTH <= BUFFER_LENGTH); sSystemErrorMessage = StandardGetBuffer(); // Lancement de la commande ok = StartProcess(sCommandLine, sSystemErrorMessage); - delete[] sCommandLine; // Message d'erreur if (!ok) { - // On passe par SecureStrcpy plutot que par sprintf en raison de l'incertitude sur les tailles - // de parametres assert(sErrorMessage[0] == '\0'); - SecureStrcpy(sErrorMessage, "unable to launch ", SYSTEM_MESSAGE_LENGTH); - SecureStrcpy(sErrorMessage, sApplicationLabel, SYSTEM_MESSAGE_LENGTH); - SecureStrcpy(sErrorMessage, " tool using \"", SYSTEM_MESSAGE_LENGTH); - SecureStrcpy(sErrorMessage, sFileAssociation, SYSTEM_MESSAGE_LENGTH); - SecureStrcpy(sErrorMessage, "\" (", SYSTEM_MESSAGE_LENGTH); - SecureStrcpy(sErrorMessage, sSystemErrorMessage, SYSTEM_MESSAGE_LENGTH); - SecureStrcpy(sErrorMessage, ")", SYSTEM_MESSAGE_LENGTH); + snprintf(sErrorMessage, SYSTEM_MESSAGE_LENGTH, "unable to launch %s tool using \"%s\" (%s)", + sApplicationLabel, sFileAssociation, sSystemErrorMessage); } } return ok; @@ -487,10 +462,10 @@ int OpenApplication(const char* sApplicationExeName, const char* sApplicationLab if (sApplicationExeName[0] != '\0') { sCommandLine = StandardGetBuffer(); - sprintf(sCommandLine, "command -v %s > /dev/null", sApplicationExeName); + snprintf(sCommandLine, BUFFER_LENGTH, "command -v %s > /dev/null", sApplicationExeName); ok = system(sCommandLine) == 0; if (!ok) - sprintf(sErrorMessage, "%s tool not installed", sApplicationLabel); + snprintf(sErrorMessage, SYSTEM_MESSAGE_LENGTH, "%s tool not installed", sApplicationLabel); } // Lancement si ok @@ -518,7 +493,8 @@ int OpenApplication(const char* sApplicationExeName, const char* sApplicationLab { ok = 0; assert(strlen(strerror(status)) < SYSTEM_MESSAGE_LENGTH / 2 - 30); - sprintf(sErrorMessage, "unable to launch %s tool (%s)", sApplicationLabel, strerror(status)); + snprintf(sErrorMessage, SYSTEM_MESSAGE_LENGTH, "unable to launch %s tool (%s)", + sApplicationLabel, strerror(status)); } } return ok; @@ -541,7 +517,7 @@ int OpenApplication(const char* sApplicationExeName, const char* sApplicationLab // Initialisations ok = 0; - sprintf(sErrorMessage, "unable to launch %s application on this OS", sApplicationLabel); + snprintf(sErrorMessage, SYSTEM_MESSAGE_LENGTH, "unable to launch %s application on this OS", sApplicationLabel); return ok; } #endif diff --git a/src/Norm/base/Portability.h b/src/Norm/base/Portability.h index 5566c1cad..feb837c60 100644 --- a/src/Norm/base/Portability.h +++ b/src/Norm/base/Portability.h @@ -191,7 +191,7 @@ using namespace std; // Encapsulation de quelques fonctions standards C, en les prefixant par p_ // Les methodes sont identiques dans le cas gcc, et reimplementees pour MS Visual C++ 2008 // (qui a "declasse" ces fonctions en DEPRECATED) -// Il manque les methodes open, sscanf, sprintf +// Il manque les methodes open, sscanf // Declaration de la structure stat #ifdef _WIN32 @@ -256,10 +256,6 @@ char* StandardGetBuffer(); // Renvoie une chaine lue depuis un fichier d'entree, et rangee dans le buffer en parametre(fonction "privee") void StandardGetInputString(char* sBuffer, FILE* fInput); -// Copie sSource vers sDest seulement si il y a la place -// Renvoie 0 si erreur, 1 sinon -int SecureStrcpy(char* sDest, const char* sSource, int nMaxLength); - // Taille maximale des messages systeme // Il faut donc prevoir un buffer de cette taille, plus 1 pour le caractere fin de chaine #define SYSTEM_MESSAGE_LENGTH 512 @@ -276,6 +272,7 @@ int SecureStrcpy(char* sDest, const char* sSource, int nMaxLength); // sApplicationLabel : libelle associe a l'application, pour fabriquer les message d'erreurs // sFileToOpen : nom du fichier a ouvrir, ayant une extension // sErrorMessage : sortie qui vaut vide si le chargement a reussi, le message d'erreur sinon +// (longueur max a prevoir: SYSTEM_MESSAGE_LENGTH) // valeur de retour : true si lancement effectue, false sinon int OpenApplication(const char* sApplicationExeName, const char* sApplicationLabel, const char* sFileToOpen, char* sErrorMessage); @@ -286,6 +283,7 @@ int OpenApplication(const char* sApplicationExeName, const char* sApplicationLab // Chargement d'une librairie partagee. // sLibraryPath : nom et chemin complet de la librairie (avec son extension). // sErrorMessage : sortie qui vaut vide si le chargement a reussi, le message d'erreur sinon +// (longueur max a prevoir: SYSTEM_MESSAGE_LENGTH) // valeur de retour : handle sur la librairie ouverte, ou NULL si echec du chargement void* LoadSharedLibrary(const char* sLibraryPath, char* sErrorMessage); diff --git a/src/Norm/base/Standard.cpp b/src/Norm/base/Standard.cpp index 58f172ec4..0dc33a8e8 100644 --- a/src/Norm/base/Standard.cpp +++ b/src/Norm/base/Standard.cpp @@ -31,9 +31,9 @@ const char* const SecondsToString(double dValue) // Formatage du resultat if (nHundredth == 0) - sprintf(sBuffer, "%d:%2.2d:%2.2d", nHours, nMinutes, nSeconds); + snprintf(sBuffer, BUFFER_LENGTH, "%d:%2.2d:%2.2d", nHours, nMinutes, nSeconds); else - sprintf(sBuffer, "%d:%2.2d:%2.2d.%2.2d", nHours, nMinutes, nSeconds, nHundredth); + snprintf(sBuffer, BUFFER_LENGTH, "%d:%2.2d:%2.2d.%2.2d", nHours, nMinutes, nSeconds, nHundredth); return sBuffer; } @@ -41,7 +41,7 @@ const char* const SecondsToString(double dValue) const char* const IntToString(int nValue) { char* sBuffer = StandardGetBuffer(); - sprintf(sBuffer, "%d", nValue); + snprintf(sBuffer, BUFFER_LENGTH, "%d", nValue); return sBuffer; } @@ -49,7 +49,7 @@ const char* const IntToString(int nValue) const char* const LongintToString(longint lValue) { char* sBuffer = StandardGetBuffer(); - sprintf(sBuffer, "%lld", lValue); + snprintf(sBuffer, BUFFER_LENGTH, "%lld", lValue); return sBuffer; } @@ -58,7 +58,7 @@ const char* const DoubleToString(double dValue) { char* sBuffer = StandardGetBuffer(); - sprintf(sBuffer, "%g", dValue); + snprintf(sBuffer, BUFFER_LENGTH, "%g", dValue); return sBuffer; } @@ -109,9 +109,9 @@ const char* const BooleanToString(boolean bValue) char* sBuffer = StandardGetBuffer(); if (bValue) - sprintf(sBuffer, "%s", "true"); + snprintf(sBuffer, BUFFER_LENGTH, "%s", "true"); else - sprintf(sBuffer, "%s", "false"); + snprintf(sBuffer, BUFFER_LENGTH, "%s", "false"); return sBuffer; } @@ -119,7 +119,7 @@ const char* const BooleanToString(boolean bValue) const char* const PointerToString(const void* pValue) { char* sBuffer = StandardGetBuffer(); - sprintf(sBuffer, "%p", pValue); + snprintf(sBuffer, BUFFER_LENGTH, "%p", pValue); return sBuffer; } diff --git a/src/Norm/base/SystemResource.cpp b/src/Norm/base/SystemResource.cpp index 2e4bc4e75..ee0057021 100644 --- a/src/Norm/base/SystemResource.cpp +++ b/src/Norm/base/SystemResource.cpp @@ -6,7 +6,7 @@ #include "Portability.h" #include "MemoryManager.h" -// Pour eviter les warning sur strcpy et sprintf +// Pour eviter les warning sur strcpy #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS #endif @@ -216,8 +216,8 @@ const char* CurrentPreciseTimestamp() SYSTEMTIME st; GetLocalTime(&st); - sprintf_s(sBuffer, 30, "%04d-%02d-%02d %02d:%02d:%02d.%03d%c", st.wYear, st.wMonth, st.wDay, st.wHour, - st.wMinute, st.wSecond, st.wMilliseconds, '\0'); + snprintf(sBuffer, BUFFER_LENGTH, "%04d-%02d-%02d %02d:%02d:%02d.%03d%c", st.wYear, st.wMonth, st.wDay, st.wHour, + st.wMinute, st.wSecond, st.wMilliseconds, '\0'); return sBuffer; } @@ -227,8 +227,8 @@ const char* CurrentTimestamp() SYSTEMTIME st; GetLocalTime(&st); - sprintf_s(sBuffer, 30, "%04d-%02d-%02d %02d:%02d:%02d%c", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, - st.wSecond, '\0'); + snprintf(sBuffer, BUFFER_LENGTH, "%04d-%02d-%02d %02d:%02d:%02d%c", st.wYear, st.wMonth, st.wDay, st.wHour, + st.wMinute, st.wSecond, '\0'); return sBuffer; } @@ -386,13 +386,13 @@ const char* GetMACAddress() // Memorisation de la nouvelle adresse que si elle est plus grande que la precedente // (ou d'une priorite plus forte, pour favoriser les cates reseau persistantes) // Pour garantir que l'on ne depend pas de l'ordre dans la liste - sprintf(sNewMACAddress, "%02x-%02x-%02x-%02x-%02x-%02x", - (unsigned char)pAdapterAddresses->PhysicalAddress[0], - (unsigned char)pAdapterAddresses->PhysicalAddress[1], - (unsigned char)pAdapterAddresses->PhysicalAddress[2], - (unsigned char)pAdapterAddresses->PhysicalAddress[3], - (unsigned char)pAdapterAddresses->PhysicalAddress[4], - (unsigned char)pAdapterAddresses->PhysicalAddress[5]); + snprintf(sNewMACAddress, sizeof(sNewMACAddress), "%02x-%02x-%02x-%02x-%02x-%02x", + (unsigned char)pAdapterAddresses->PhysicalAddress[0], + (unsigned char)pAdapterAddresses->PhysicalAddress[1], + (unsigned char)pAdapterAddresses->PhysicalAddress[2], + (unsigned char)pAdapterAddresses->PhysicalAddress[3], + (unsigned char)pAdapterAddresses->PhysicalAddress[4], + (unsigned char)pAdapterAddresses->PhysicalAddress[5]); if (nPriority > nBestPriority || strcmp(sNewMACAddress, sMACAddress) > 0) strcpy(sMACAddress, sNewMACAddress); if (bDisplayDetails) @@ -535,8 +535,8 @@ static char* GetOsVersion() osInfo.dwOSVersionInfoSize = sizeof(osInfo); if (fxPtr(&osInfo) == 0) { - sprintf_s(sWindowsVersion, "windows %d.%d (%d)", osInfo.dwMajorVersion, - osInfo.dwMinorVersion, osInfo.dwBuildNumber); + snprintf(sWindowsVersion, sizeof(sWindowsVersion), "windows %d.%d (%d)", + osInfo.dwMajorVersion, osInfo.dwMinorVersion, osInfo.dwBuildNumber); } } } @@ -547,16 +547,8 @@ const char* GetSystemInfos() { char* sInfo = StandardGetBuffer(); - // Nom du processeur - sInfo[0] = '\0'; - SecureStrcpy(sInfo, "cpu=", BUFFER_LENGTH); - SecureStrcpy(sInfo, GetProcessorName(), BUFFER_LENGTH); - SecureStrcpy(sInfo, "\n", BUFFER_LENGTH); - - // OS - SecureStrcpy(sInfo, "os=", BUFFER_LENGTH); - SecureStrcpy(sInfo, GetOsVersion(), BUFFER_LENGTH); - SecureStrcpy(sInfo, "\n", BUFFER_LENGTH); + // Nom du processeur et de l'OS + snprintf(sInfo, BUFFER_LENGTH, "cpu=%s\nos=%s\n", GetProcessorName(), GetOsVersion()); return sInfo; } @@ -834,7 +826,7 @@ const char* CurrentPreciseTimestamp() milliseconds = tv.tv_usec / 1000; /* Print the formatted time, in seconds, followed by a decimal point and the milliseconds. */ - sprintf(sBuffer, "%s.%03ld", time_string, milliseconds); + snprintf(sBuffer, BUFFER_LENGTH, "%s.%03ld", time_string, milliseconds); return sBuffer; } @@ -1130,7 +1122,7 @@ int IsVirtual(const char* sInterfaceName) // L'heuristique ne fonctionne pas, on ne sait pas si c'est virtuel ou non return 0; - sprintf(sDeviceDirectory, "%s%s/device/", sRep, sInterfaceName); + snprintf(sDeviceDirectory, sizeof(sDeviceDirectory), "%s%s/device/", sRep, sInterfaceName); if (IsDirectory(sDeviceDirectory)) // C'est une interface physique return 0; @@ -1226,10 +1218,11 @@ const char* GetMACAddress() // Si l'interface est prioritaire if (nPriority >= nBestPriority) { - sprintf(sNewMACAddress, "%02x-%02x-%02x-%02x-%02x-%02x", - (unsigned char)s->sll_addr[0], (unsigned char)s->sll_addr[1], - (unsigned char)s->sll_addr[2], (unsigned char)s->sll_addr[3], - (unsigned char)s->sll_addr[4], (unsigned char)s->sll_addr[5]); + snprintf(sNewMACAddress, sizeof(sNewMACAddress), + "%02x-%02x-%02x-%02x-%02x-%02x", (unsigned char)s->sll_addr[0], + (unsigned char)s->sll_addr[1], (unsigned char)s->sll_addr[2], + (unsigned char)s->sll_addr[3], (unsigned char)s->sll_addr[4], + (unsigned char)s->sll_addr[5]); // On garde la prioritaire // En cas d'egalite, on garde l'adresse qui est la plus grande suivant @@ -1366,6 +1359,7 @@ const char* GetSystemInfos() int i = 0; int nLineCount; char* sInfo = StandardGetBuffer(); + int nPos; char c; struct utsname buffer; bool bOk; @@ -1401,15 +1395,9 @@ const char* GetSystemInfos() if (uname(&buffer) >= 0) { bOk = true; - bOk = bOk and SecureStrcpy(sInfo, "system=", BUFFER_LENGTH); - bOk = bOk and SecureStrcpy(sInfo, buffer.sysname, BUFFER_LENGTH); - bOk = bOk and SecureStrcpy(sInfo, "\n", BUFFER_LENGTH); - bOk = bOk and SecureStrcpy(sInfo, "release=", BUFFER_LENGTH); - bOk = bOk and SecureStrcpy(sInfo, buffer.release, BUFFER_LENGTH); - bOk = bOk and SecureStrcpy(sInfo, "\n", BUFFER_LENGTH); - bOk = bOk and SecureStrcpy(sInfo, "version=", BUFFER_LENGTH); - bOk = bOk and SecureStrcpy(sInfo, buffer.version, BUFFER_LENGTH); - bOk = bOk and SecureStrcpy(sInfo, "\n", BUFFER_LENGTH); + nPos = (int)strlen(sInfo); + snprintf(&sInfo[nPos], BUFFER_LENGTH - nPos, "system=%s\nrelease=%s\nversion=%s\n", buffer.sysname, + buffer.release, buffer.version); } return sInfo; } diff --git a/src/Norm/genere/Attribute.h b/src/Norm/genere/Attribute.h index 33eced422..39d349873 100644 --- a/src/Norm/genere/Attribute.h +++ b/src/Norm/genere/Attribute.h @@ -53,7 +53,7 @@ class Attribute : public ManagedObject // Champs de la cle // Name - const ALString& GetKey() const; + const ALString& GetKey() const override; //////////////////////////////////////////////////////// // Fonctionnalites generiques @@ -77,22 +77,22 @@ class Attribute : public ManagedObject }; // Nombre de champs - int GetFieldNumber() const; + int GetFieldNumber() const override; // Acces generique aux champs, par une valeur de // type chaine de caracteres // (les champs derives sont ignores en ecriture) - void SetFieldAt(int nFieldIndex, const char* sValue); - const char* GetFieldAt(int nFieldIndex) const; + void SetFieldAt(int nFieldIndex, const char* sValue) override; + const char* GetFieldAt(int nFieldIndex) const override; // Nom d'un champ d'apres son index - const ALString GetFieldNameAt(int nFieldIndex) const; + const ALString GetFieldNameAt(int nFieldIndex) const override; // Libelle d'un champ d'apres son index - const ALString GetFieldLabelAt(int nFieldIndex) const; + const ALString GetFieldLabelAt(int nFieldIndex) const override; // Nom de stockage d'un champ d'apres son index - const ALString GetFieldStorageNameAt(int nFieldIndex) const; + const ALString GetFieldStorageNameAt(int nFieldIndex) const override; // Parametrage du separateur de champs (par defaut: '\t') static void SetFieldSeparator(char cValue); @@ -171,11 +171,11 @@ class Attribute : public ManagedObject //// Implementation protected: // Implementation des methodes virtuelles de ManagedObject - ManagedObject* CloneManagedObject() const; - boolean GetFieldStored(int nFieldIndex) const; - IntVector* GetStoredFieldIndexes() const; - CompareFunction GetCompareKeyFunction() const; - char GetSeparator() const; + ManagedObject* CloneManagedObject() const override; + boolean GetFieldStored(int nFieldIndex) const override; + IntVector* GetStoredFieldIndexes() const override; + CompareFunction GetCompareKeyFunction() const override; + char GetSeparator() const override; // Exemplaire d'objet gere static Attribute managedObjectClass; diff --git a/src/Norm/samples/sample3/PRWorkerView.h b/src/Norm/samples/sample3/PRWorkerView.h index 408afcb0f..8333f2b8b 100644 --- a/src/Norm/samples/sample3/PRWorkerView.h +++ b/src/Norm/samples/sample3/PRWorkerView.h @@ -54,7 +54,7 @@ class PRWorkerView : public UIObjectView void ActionInspectProfessionnalAddress(); // Acces a l'objet edite par la vue - void SetObject(Object* object); + void SetObject(Object* object) override; PRWorker* GetWorker(); // ## diff --git a/src/Parallel/PLSamples/PEPi.cpp b/src/Parallel/PLSamples/PEPi.cpp index e5004228e..33eab1645 100644 --- a/src/Parallel/PLSamples/PEPi.cpp +++ b/src/Parallel/PLSamples/PEPi.cpp @@ -78,7 +78,7 @@ const ALString PEPi::GetObjectLabel() const void PEPi::ComputePi() { PEPiTask piTask; - char cPi[29]; + char sPi[30]; ALString sTmp; // Parametrage et lancement de la tache de calcul de Pi @@ -86,8 +86,8 @@ void PEPi::ComputePi() piTask.ComputePi(); // Collecte des resultats, avec le maximum de precision - sprintf(cPi, "%.15g", piTask.GetComputedPi()); - SetPi(cPi); + snprintf(sPi, sizeof(sPi), "%.15g", piTask.GetComputedPi()); + SetPi(sPi); SetElapsedTime(piTask.GetJobElapsedTime()); }