Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more Codacy issues #4267

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions INSTALL.GIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Just run:

and follow the instruction on [Viewer Debugging](https://tesseract-ocr.github.io/tessdoc/ViewerDebugging.html).


## cmake

There is alternative build system based on multiplatform [cmake](https://cmake.org/)
Expand All @@ -61,7 +60,6 @@ There is alternative build system based on multiplatform [cmake](https://cmake.o
cd build && cmake .. && make
sudo make install


### WINDOWS

See the [documentation](https://tesseract-ocr.github.io/tessdoc/) for more information on this.
6 changes: 3 additions & 3 deletions doc/generate_manpages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ if [[ -z "${asciidoc}" ]] || [[ -z "${xsltproc}" ]]; then
else
for src in *.asc; do
pagename=${src/.asc/}
(${asciidoc} -d manpage ${src} &&
${asciidoc} -d manpage -b docbook ${src} &&
${xsltproc} --nonet ${man_xslt} ${pagename}.xml) ||
(${asciidoc} -d manpage "${src}" &&
${asciidoc} -d manpage -b docbook "${src}" &&
${xsltproc} --nonet ${man_xslt} "${pagename}".xml) ||
echo "Error generating ${pagename}"
done
fi
Expand Down
1 change: 0 additions & 1 deletion src/arch/intsimdmatrixavx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ static void matrixDotVector(int dim1, int dim2, const int8_t *wi, const double *
output += group_size;
}
group_size /= 2;
w_step /= 2;

if (output + group_size <= rounded_num_out) {
PartialMatrixDotVector8(wi, scales, u, rounded_num_in, v);
Expand Down
3 changes: 1 addition & 2 deletions src/ccmain/fixspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ int16_t Tesseract::eval_word_spacing(WERD_RES_LIST &word_res_list) {
bool prev_char_1 = false; // prev ch a "1/I/l"?
bool prev_char_digit = false; // prev ch 2..9 or 0
const char *punct_chars = "!\"`',.:;";
bool prev_char_punct = false;

do {
// current word
WERD_RES *word = word_res_it.data();
Expand Down Expand Up @@ -325,6 +323,7 @@ int16_t Tesseract::eval_word_spacing(WERD_RES_LIST &word_res_list) {
/* Add 1 to total score for every joined punctuation regardless of context
and rejtn */
if (tessedit_prefer_joined_punct) {
bool prev_char_punct;
for (i = 0, offset = 0, prev_char_punct = false; i < word_len;
offset += word->best_choice->unichar_lengths()[i++]) {
bool current_char_punct =
Expand Down
12 changes: 4 additions & 8 deletions src/classify/intmatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,6 @@ void IntegerMatcher::DebugFeatureProtoError(INT_CLASS_STRUCT *ClassTemplate, BIT
uint16_t ProtoNum;
uint8_t ProtoWordNum;
PROTO_SET_STRUCT *ProtoSet;
uint16_t ActualProtoNum;

if (PrintMatchSummaryOn(Debug)) {
tprintf("Configuration Mask:\n");
Expand All @@ -912,9 +911,8 @@ void IntegerMatcher::DebugFeatureProtoError(INT_CLASS_STRUCT *ClassTemplate, BIT
if (PrintMatchSummaryOn(Debug)) {
tprintf("Proto Mask:\n");
for (ProtoSetIndex = 0; ProtoSetIndex < ClassTemplate->NumProtoSets; ProtoSetIndex++) {
ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET);
for (ProtoWordNum = 0; ProtoWordNum < 2; ProtoWordNum++, ProtoMask++) {
ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET);
uint16_t ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET);
for (ProtoNum = 0; ((ProtoNum < (PROTOS_PER_PROTO_SET >> 1)) &&
(ActualProtoNum < ClassTemplate->NumProtos));
ProtoNum++, ActualProtoNum++) {
Expand All @@ -934,7 +932,7 @@ void IntegerMatcher::DebugFeatureProtoError(INT_CLASS_STRUCT *ClassTemplate, BIT
tprintf("Proto Evidence:\n");
for (ProtoSetIndex = 0; ProtoSetIndex < ClassTemplate->NumProtoSets; ProtoSetIndex++) {
ProtoSet = ClassTemplate->ProtoSets[ProtoSetIndex];
ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET);
uint16_t ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET);
for (ProtoNum = 0;
((ProtoNum < PROTOS_PER_PROTO_SET) && (ActualProtoNum < ClassTemplate->NumProtos));
ProtoNum++, ActualProtoNum++) {
Expand Down Expand Up @@ -991,7 +989,6 @@ void IntegerMatcher::DisplayProtoDebugInfo(INT_CLASS_STRUCT *ClassTemplate, BIT_
const ScratchEvidence &tables,
bool SeparateDebugWindows) {
uint16_t ProtoNum;
uint16_t ActualProtoNum;
PROTO_SET_STRUCT *ProtoSet;
int ProtoSetIndex;

Expand All @@ -1003,7 +1000,7 @@ void IntegerMatcher::DisplayProtoDebugInfo(INT_CLASS_STRUCT *ClassTemplate, BIT_

for (ProtoSetIndex = 0; ProtoSetIndex < ClassTemplate->NumProtoSets; ProtoSetIndex++) {
ProtoSet = ClassTemplate->ProtoSets[ProtoSetIndex];
ActualProtoNum = ProtoSetIndex * PROTOS_PER_PROTO_SET;
uint16_t ActualProtoNum = ProtoSetIndex * PROTOS_PER_PROTO_SET;
for (ProtoNum = 0;
((ProtoNum < PROTOS_PER_PROTO_SET) && (ActualProtoNum < ClassTemplate->NumProtos));
ProtoNum++, ActualProtoNum++) {
Expand Down Expand Up @@ -1076,13 +1073,12 @@ void ScratchEvidence::UpdateSumOfProtoEvidences(INT_CLASS_STRUCT *ClassTemplate,
uint16_t ProtoNum;
PROTO_SET_STRUCT *ProtoSet;
int NumProtos;
uint16_t ActualProtoNum;

NumProtos = ClassTemplate->NumProtos;

for (ProtoSetIndex = 0; ProtoSetIndex < ClassTemplate->NumProtoSets; ProtoSetIndex++) {
ProtoSet = ClassTemplate->ProtoSets[ProtoSetIndex];
ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET);
uint16_t ActualProtoNum = (ProtoSetIndex * PROTOS_PER_PROTO_SET);
for (ProtoNum = 0; ((ProtoNum < PROTOS_PER_PROTO_SET) && (ActualProtoNum < NumProtos));
ProtoNum++, ActualProtoNum++) {
int temp = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/dict/dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ bool Dict::valid_punctuation(const WERD_CHOICE &word) {
}
WERD_CHOICE new_word(word.unicharset());
auto last_index = word.length() - 1;
int new_len = 0;
int new_len;
for (unsigned i = 0; i <= last_index; ++i) {
UNICHAR_ID unichar_id = (word.unichar_id(i));
if (getUnicharset().get_ispunctuation(unichar_id)) {
Expand Down
6 changes: 2 additions & 4 deletions src/textord/tablefind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,6 @@ bool TableFinder::HasWideOrNoInterWordGap(ColPartition *part) const {
}

// Variables used to compute inter-blob spacing.
int current_x0 = -1;
int current_x1 = -1;
int previous_x1 = -1;
// Stores the maximum gap detected.
int largest_partition_gap_found = -1;
Expand All @@ -897,8 +895,8 @@ bool TableFinder::HasWideOrNoInterWordGap(ColPartition *part) const {

for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
BLOBNBOX *blob = it.data();
current_x0 = blob->bounding_box().left();
current_x1 = blob->bounding_box().right();
int current_x0 = blob->bounding_box().left();
int current_x1 = blob->bounding_box().right();
if (previous_x1 != -1) {
int gap = current_x0 - previous_x1;

Expand Down
1 change: 0 additions & 1 deletion unittest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
* [Lohit-Hindi.ttf](https://raw.githubusercontent.com/pratul/packageofpractices/master/assets/fonts/Lohit-Hindi.ttf)
* [UnBatang.ttf](https://raw.githubusercontent.com/byrongibson/fonts/master/backup/truetype.original/unfonts-core/UnBatang.ttf)


## Run tests

To run the tests, do the following in tesseract folder
Expand Down
24 changes: 12 additions & 12 deletions unittest/fuzzers/oss-fuzz-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
#
################################################################################

cd $SRC/leptonica
cd "$SRC"/leptonica
./autogen.sh
./configure --disable-shared
make SUBDIRS=src install -j$(nproc)
make SUBDIRS=src install -j"$(nproc)"
ldconfig

cd $SRC/tesseract
cd "$SRC"/tesseract
./autogen.sh
CXXFLAGS="$CXXFLAGS -D_GLIBCXX_DEBUG" ./configure --disable-graphics --disable-shared
make -j$(nproc)
make -j"$(nproc)"

# Get the models which are needed for the fuzzers.

mkdir -p $OUT/tessdata
mkdir -p "$OUT"/tessdata
(
cd $OUT/tessdata
cd "$OUT"/tessdata
test -f eng.traineddata || \
curl -L -O https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata
)
Expand All @@ -44,19 +44,19 @@ LEPTONICA_LIBS=$(pkg-config --static --libs lept)
LIBTIFF_LIBS=$(pkg-config --static --libs libtiff-4 | sed 's/ -lm//')

$CXX $CXXFLAGS \
-I $SRC/tesseract/include \
$SRC/tesseract/unittest/fuzzers/fuzzer-api.cpp -o $OUT/fuzzer-api \
$SRC/tesseract/.libs/libtesseract.a \
-I "$SRC"/tesseract/include \
"$SRC"/tesseract/unittest/fuzzers/fuzzer-api.cpp -o "$OUT"/fuzzer-api \
"$SRC"/tesseract/.libs/libtesseract.a \
$LEPTONICA_CFLAGS \
-Wl,-Bstatic $LEPTONICA_LIBS $LIBTIFF_LIBS -Wl,-Bdynamic \
$LIB_FUZZING_ENGINE

$CXX $CXXFLAGS \
-DTESSERACT_FUZZER_WIDTH=512 \
-DTESSERACT_FUZZER_HEIGHT=256 \
-I $SRC/tesseract/include \
$SRC/tesseract/unittest/fuzzers/fuzzer-api.cpp -o $OUT/fuzzer-api-512x256 \
$SRC/tesseract/.libs/libtesseract.a \
-I "$SRC"/tesseract/include \
"$SRC"/tesseract/unittest/fuzzers/fuzzer-api.cpp -o "$OUT"/fuzzer-api-512x256 \
"$SRC"/tesseract/.libs/libtesseract.a \
$LEPTONICA_CFLAGS \
-Wl,-Bstatic $LEPTONICA_LIBS $LIBTIFF_LIBS -Wl,-Bdynamic \
$LIB_FUZZING_ENGINE
Loading