[frameworks/kcodecs] src/probers: [KEncodingProber] SBCS: Replace unbounded array pointer with span

Stefan Brüns <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 00a9db455e1fb9f94f44118ef391f472e3178649 by Stefan Brüns.
Committed on 08/08/2026 at 13:37.
Pushed by bruns into branch 'master'.

[KEncodingProber] SBCS: Replace unbounded array pointer with span

M  +1    -1    src/probers/LangBulgarianModel.cpp
M  +7    -7    src/probers/LangCyrillicModel.cpp
M  +3    -3    src/probers/LangGreekModel.cpp
M  +2    -2    src/probers/LangHebrewModel.cpp
M  +3    -3    src/probers/LangHungarianModel.cpp
M  +2    -2    src/probers/LangThaiModel.cpp
M  +1    -1    src/probers/nsSBCharSetProber.cpp
M  +2    -1    src/probers/nsSBCharSetProber.h

https://invent.kde.org/frameworks/kcodecs/-/commit/00a9db455e1fb9f94f44118ef391f472e3178649

diff --git a/src/probers/LangBulgarianModel.cpp b/src/probers/LangBulgarianModel.cpp
index dc5ec88..501bab7 100644
--- a/src/probers/LangBulgarianModel.cpp
+++ b/src/probers/LangBulgarianModel.cpp
@@ -63,7 +63,7 @@ const unsigned char win1251BulgarianCharToOrderMap[] = {
 // first 1024 sequences:3.0618%
 // rest  sequences:     0.2992%
 // negative sequences:  0.0020%
-const char BulgarianLangModel[] = {
+constexpr std::array<const uint8_t, 64 * 64> BulgarianLangModel = {
     0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
     0, 3, 3, 3, 2, 2, 3, 2, 2, 1, 2, 2, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3,
diff --git a/src/probers/LangCyrillicModel.cpp b/src/probers/LangCyrillicModel.cpp
index 265e939..ee9663f 100644
--- a/src/probers/LangCyrillicModel.cpp
+++ b/src/probers/LangCyrillicModel.cpp
@@ -115,7 +115,7 @@ const unsigned char IBM866_CharToOrderMap[] = {
 // first 1024 sequences: 2.3389%
 // rest  sequences:      0.1237%
 // negative sequences:   0.0009%
-const char RussianLangModel[] = {
+constexpr std::array<const uint8_t, 64 * 64> RussianLangModel = {
     0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 3, 3, 3, 3, 1, 3, 3, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
     3, 3, 0, 3, 2, 2, 2, 2, 2, 0, 0, 2, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 2,
@@ -197,15 +197,15 @@ const char RussianLangModel[] = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
 };
 
-const SequenceModel Koi8rModel = {KOI8R_CharToOrderMap, RussianLangModel, (float)0.976601, false, "KOI8-R"};
+constexpr SequenceModel Koi8rModel = {KOI8R_CharToOrderMap, RussianLangModel, 0.976601f, false, "KOI8-R"};
 
-const SequenceModel Win1251Model = {win1251_CharToOrderMap, RussianLangModel, (float)0.976601, false, "windows-1251"};
+constexpr SequenceModel Win1251Model = {win1251_CharToOrderMap, RussianLangModel, 0.976601f, false, "windows-1251"};
 
-const SequenceModel Latin5Model = {latin5_CharToOrderMap, RussianLangModel, (float)0.976601, false, "ISO-8859-5"};
+constexpr SequenceModel Latin5Model = {latin5_CharToOrderMap, RussianLangModel, 0.976601f, false, "ISO-8859-5"};
 
-const SequenceModel MacCyrillicModel = {macCyrillic_CharToOrderMap, RussianLangModel, (float)0.976601, false, "x-mac-cyrillic"};
+constexpr SequenceModel MacCyrillicModel = {macCyrillic_CharToOrderMap, RussianLangModel, 0.976601f, false, "x-mac-cyrillic"};
 
-const SequenceModel Ibm866Model = {IBM866_CharToOrderMap, RussianLangModel, (float)0.976601, false, "IBM866"};
+constexpr SequenceModel Ibm866Model = {IBM866_CharToOrderMap, RussianLangModel, 0.976601f, false, "IBM866"};
 
-const SequenceModel Ibm855Model = {IBM855_CharToOrderMap, RussianLangModel, (float)0.976601, false, "IBM855"};
+constexpr SequenceModel Ibm855Model = {IBM855_CharToOrderMap, RussianLangModel, 0.976601f, false, "IBM855"};
 }
diff --git a/src/probers/LangGreekModel.cpp b/src/probers/LangGreekModel.cpp
index 02c2ed3..fd9bb74 100644
--- a/src/probers/LangGreekModel.cpp
+++ b/src/probers/LangGreekModel.cpp
@@ -60,7 +60,7 @@ const unsigned char win1253_CharToOrderMap[] = {
 // first 1024 sequences:1.7001%
 // rest  sequences:     0.0359%
 // negative sequences:  0.0148%
-const char GreekLangModel[] = {
+constexpr std::array<const uint8_t, 64 * 64> GreekLangModel = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 0, 2, 2, 3, 3, 0, 3, 0, 3, 2, 0, 3, 3, 3, 0, 3, 0, 0, 0, 2, 0, 0, 0,
     0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 0, 3, 3, 0, 3, 2, 3, 3, 0, 3, 2, 3, 3, 3, 0, 0, 3, 0, 3, 0, 3, 3,
@@ -142,7 +142,7 @@ const char GreekLangModel[] = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 };
 
-const SequenceModel Latin7Model = {Latin7_CharToOrderMap, GreekLangModel, (float)0.982851, false, "ISO-8859-7"};
+constexpr SequenceModel Latin7Model = {Latin7_CharToOrderMap, GreekLangModel, 0.982851f, false, "ISO-8859-7"};
 
-const SequenceModel Win1253Model = {win1253_CharToOrderMap, GreekLangModel, (float)0.982851, false, "windows-1253"};
+constexpr SequenceModel Win1253Model = {win1253_CharToOrderMap, GreekLangModel, 0.982851f, false, "windows-1253"};
 }
diff --git a/src/probers/LangHebrewModel.cpp b/src/probers/LangHebrewModel.cpp
index ee42e0e..6c94073 100644
--- a/src/probers/LangHebrewModel.cpp
+++ b/src/probers/LangHebrewModel.cpp
@@ -44,7 +44,7 @@ const unsigned char win1255_CharToOrderMap[] = {
 // first 1024 sequences: 1.5981%
 // rest  sequences:      0.087%
 // negative sequences:   0.0015%
-const char HebrewLangModel[] = {
+constexpr std::array<const uint8_t, 64 * 64> HebrewLangModel = {
     0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 2, 1, 2, 0, 1, 0, 0, 3, 0, 3, 1, 0, 0, 1, 3, 2, 0, 1, 1, 2, 0, 2, 2, 2, 1, 1, 1,
     1, 2, 1, 1, 1, 2, 0, 0, 2, 2, 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1, 2, 1, 2, 1, 2, 0, 0,
     2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
@@ -126,5 +126,5 @@ const char HebrewLangModel[] = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0,
 };
 
-const SequenceModel Win1255Model = {win1255_CharToOrderMap, HebrewLangModel, (float)0.984004, false, "windows-1255"};
+constexpr SequenceModel Win1255Model = {win1255_CharToOrderMap, HebrewLangModel, 0.984004f, false, "windows-1255"};
 }
diff --git a/src/probers/LangHungarianModel.cpp b/src/probers/LangHungarianModel.cpp
index c472459..474a34e 100644
--- a/src/probers/LangHungarianModel.cpp
+++ b/src/probers/LangHungarianModel.cpp
@@ -50,7 +50,7 @@ const unsigned char win1250HungarianCharToOrderMap[] = {
 // first 1024 sequences:5.2623%
 // rest  sequences:     0.8894%
 // negative sequences:  0.0009%
-const char HungarianLangModel[] = {
+constexpr std::array<const uint8_t, 64 * 64> HungarianLangModel = {
     0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2,
     2, 3, 3, 1, 1, 2, 2, 2, 2, 2, 1, 2, 3, 2, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 1, 2, 3, 3, 3, 3, 2, 3, 3, 1, 1, 3, 3, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 2, 1, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 1, 1, 3, 2,
@@ -132,7 +132,7 @@ const char HungarianLangModel[] = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 };
 
-const SequenceModel Latin2HungarianModel = {Latin2_HungarianCharToOrderMap, HungarianLangModel, (float)0.947368, true, "ISO-8859-2"};
+constexpr SequenceModel Latin2HungarianModel = {Latin2_HungarianCharToOrderMap, HungarianLangModel, 0.947368f, true, "ISO-8859-2"};
 
-const SequenceModel Win1250HungarianModel = {win1250HungarianCharToOrderMap, HungarianLangModel, (float)0.947368, true, "windows-1250"};
+constexpr SequenceModel Win1250HungarianModel = {win1250HungarianCharToOrderMap, HungarianLangModel, 0.947368f, true, "windows-1250"};
 }
diff --git a/src/probers/LangThaiModel.cpp b/src/probers/LangThaiModel.cpp
index f7de19b..e493c59 100644
--- a/src/probers/LangThaiModel.cpp
+++ b/src/probers/LangThaiModel.cpp
@@ -41,7 +41,7 @@ const unsigned char TIS620CharToOrderMap[] = {
 // first 1024 sequences:7.3177%
 // rest  sequences:     1.0230%
 // negative sequences:  0.0436%
-const char ThaiLangModel[] = {
+constexpr std::array<const uint8_t, 64 * 64> ThaiLangModel = {
     0, 1, 3, 3, 3, 3, 0, 0, 3, 3, 0, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 0, 0, 0, 1, 3, 0, 3, 3, 2, 3, 3, 0, 1, 2, 3, 3, 3,
     3, 0, 2, 0, 2, 0, 0, 3, 2, 1, 2, 2, 3, 0, 3, 3, 2, 3, 0, 0, 3, 3, 0, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 2, 3, 0, 2, 2, 2, 3, 0, 2, 3, 0, 0, 0, 0, 1,
     0, 1, 2, 3, 1, 1, 3, 2, 2, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 3, 2, 3,
@@ -123,5 +123,5 @@ const char ThaiLangModel[] = {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 };
 
-const SequenceModel TIS620ThaiModel = {TIS620CharToOrderMap, ThaiLangModel, (float)0.926386, false, "TIS-620"};
+constexpr SequenceModel TIS620ThaiModel = {TIS620CharToOrderMap, ThaiLangModel, 0.926386f, false, "TIS-620"};
 }
diff --git a/src/probers/nsSBCharSetProber.cpp b/src/probers/nsSBCharSetProber.cpp
index ccd8874..2a7ecc7 100644
--- a/src/probers/nsSBCharSetProber.cpp
+++ b/src/probers/nsSBCharSetProber.cpp
@@ -28,7 +28,7 @@ nsProbingState nsSingleByteCharSetProber<Reversed>::HandleData(const char *aBuf,
 
             if (mLastOrder < SAMPLE_SIZE) {
                 unsigned int index = Reversed ? mLastOrder + (SAMPLE_SIZE * order) : (mLastOrder * SAMPLE_SIZE) + order;
-                ++(mSeqCounters[(int)mModel->precedenceMatrix[index]]);
+                ++(mSeqCounters[mModel->precedenceMatrix[index]]);
             }
         }
         mLastOrder = order;
diff --git a/src/probers/nsSBCharSetProber.h b/src/probers/nsSBCharSetProber.h
index b8e853e..3a33e5e 100644
--- a/src/probers/nsSBCharSetProber.h
+++ b/src/probers/nsSBCharSetProber.h
@@ -10,6 +10,7 @@
 #include "nsCharSetProber.h"
 
 #include <array>
+#include <span>
 
 #define SAMPLE_SIZE 64
 #define SYMBOL_CAT_ORDER 250
@@ -18,7 +19,7 @@ namespace kencodingprober
 {
 typedef struct {
     const unsigned char *charToOrderMap; // [256] table use to find a char's order
-    const char *precedenceMatrix; // [SAMPLE_SIZE][SAMPLE_SIZE]; table to find a 2-char sequence's frequency
+    const std::span<const uint8_t, 64 * 64> precedenceMatrix; // [SAMPLE_SIZE][SAMPLE_SIZE]; table to find a 2-char sequence's frequency
     float mTypicalPositiveRatio; // = freqSeqs / totalSeqs
     bool keepEnglishLetter; // says if this script contains English characters (not implemented)
     const char *charsetName;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.