Skip to content

Commit eb6f8c5

Browse files
committed
Improve portability by integral division
This is a continuation after the commit 755f31e ("3.12.0") which removed the dependency to the float log. Once we find quartile values in TLSH, we perform a float division to get q1/q3 and q2/q3 in percentage (and taken the mod 16) but lacks portability (and has a bug which the committer explains later). If we have a 32-bit divider, a 64-bit / 32-bit division is not that a big cost (it's theoretically one instruction in x86 because the DIV instruction performs a 64-bit / 32-bit division). It also fixes the problem of arithmetic overflow calculating unsigned 32-bit (q1*100) and (q2*100) (if they overflow, the ratio will be an unexpected value).
1 parent 25bc5d2 commit eb6f8c5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

‎src/tlsh_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ void TlshImpl::final(int fc_cons_option)
784784
}
785785

786786
this->lsh_bin.Lvalue = l_capturing(this->data_len);
787-
this->lsh_bin.Q.QR.Q1ratio = (unsigned int) ((float)(q1*100)/(float) q3) % 16;
788-
this->lsh_bin.Q.QR.Q2ratio = (unsigned int) ((float)(q2*100)/(float) q3) % 16;
787+
this->lsh_bin.Q.QR.Q1ratio = (unsigned int) ((unsigned long long) q1 * 100 / q3) % 16;
788+
this->lsh_bin.Q.QR.Q2ratio = (unsigned int) ((unsigned long long) q2 * 100 / q3) % 16;
789789
this->lsh_code_valid = true;
790790
}
791791

0 commit comments

Comments
 (0)