Skip to content

Commit

Permalink
Merge pull request #78 from ederc/input-overflow-fix
Browse files Browse the repository at this point in the history
Input overflow fix
  • Loading branch information
mohabsafey authored Sep 11, 2023
2 parents 0c38068 + 20cd332 commit e706927
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ checkdiff = test/diff/diff_cp_d_3_n_4_p_2.sh \
test/diff/diff_bug_2nd_prime_bad.sh \
test/diff/diff_bug_68.sh \
test/diff/diff_mq_2_1.sh \
test/diff/diff_xy-qq.sh
test/diff/diff_xy-qq.sh \
test/diff/diff_input-overflow-8.sh \
test/diff/diff_input-overflow-16.sh

# dist_check_DATA = test/input_files
neogb_io_SOURCES = test/neogb/io/validate_input_data.c
Expand Down
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,11 @@ AC_CONFIG_LINKS([
input_files/mq_2_1.ms:input_files/mq_2_1.ms
output_files/mq_2_1.res:output_files/mq_2_1.res
test/diff/diff_mq_2_1.sh:test/diff/diff_mq_2_1.sh
input_files/input-overflow-8.ms:input_files/input-overflow-8.ms
output_files/input-overflow-8.res:output_files/input-overflow-8.res
test/diff/diff_input-overflow-8.sh:test/diff/diff_input-overflow-8.sh
input_files/input-overflow-16.ms:input_files/input-overflow-16.ms
output_files/input-overflow-16.res:output_files/input-overflow-16.res
test/diff/diff_input-overflow-16.sh:test/diff/diff_input-overflow-16.sh
])
AC_OUTPUT
4 changes: 4 additions & 0 deletions input_files/input-overflow-16.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
y,x
65519
x^2+128333*x*y-12*y,
y^2-x
4 changes: 4 additions & 0 deletions input_files/input-overflow-8.ms
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
y,x
31
x^2+128333*x*y-12*y,
y^2-x
14 changes: 14 additions & 0 deletions output_files/input-overflow-16.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[0, [65519,
2,
4,
['y', 'x'],
[0, 1],
[1,
[[4,
[0, 65375, 599, 21103, 1]],
[0,
[1]],
[
[[3,
[0, 39978, 62904, 51433]]]
]]]]]:
14 changes: 14 additions & 0 deletions output_files/input-overflow-8.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[0, [31,
2,
4,
['y', 'x'],
[0, 1],
[1,
[[4,
[0, 11, 18, 13, 1]],
[0,
[1]],
[
[[3,
[0, 14, 21, 5]]]
]]]]]:
8 changes: 6 additions & 2 deletions src/neogb/basis.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static inline void normalize_initial_basis_ff_8(
for (i = 0; i < ld; ++i) {
cf8_t *row = cf[hm[i][COEFFS]];

const uint8_t inv = mod_p_inverse_8(row[0], fc8);
const uint8_t inv = mod_p_inverse_8((int16_t)row[0], (int16_t)fc8);
const len_t os = hm[i][PRELOOP];
const len_t len = hm[i][LENGTH];

Expand Down Expand Up @@ -297,7 +297,7 @@ static inline void normalize_initial_basis_ff_16(
for (i = 0; i < ld; ++i) {
cf16_t *row = cf[hm[i][COEFFS]];

const uint16_t inv = mod_p_inverse_16(row[0], fc16);
const uint16_t inv = mod_p_inverse_16((int32_t)row[0], (int32_t)fc16);
const len_t os = hm[i][PRELOOP];
const len_t len = hm[i][LENGTH];

Expand Down Expand Up @@ -362,6 +362,10 @@ static inline void normalize_initial_basis_ff_32(
row[j+2] = (cf32_t)tmp3;
row[j+3] = (cf32_t)tmp4;
}
for (j = 0; j < len; ++j) {
printf("%u\n", row[j]);
}
printf("\n");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/neogb/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void import_input_data(
for (j = off; j < off+lens[i]; ++j) {
/* make coefficient positive */
cfs_ff[j] += (cfs_ff[j] >> 31) & fc;
cf8[j-off] = (cf8_t)cfs_ff[j];
cf8[j-off] = (cf8_t)(cfs_ff[j] % fc);
}
sort_terms_ff_8(&(bs->cf_8[ctr]), &(bs->hm[ctr]), ht);
ctr++;
Expand All @@ -336,7 +336,7 @@ void import_input_data(
for (j = off; j < off+lens[i]; ++j) {
/* make coefficient positive */
cfs_ff[j] += (cfs_ff[j] >> 31) & fc;
cf16[j-off] = (cf16_t)cfs_ff[j];
cf16[j-off] = (cf16_t)(cfs_ff[j] % fc);
}
sort_terms_ff_16(&(bs->cf_16[ctr]), &(bs->hm[ctr]), ht);
ctr++;
Expand All @@ -354,7 +354,7 @@ void import_input_data(
for (j = off; j < off+lens[i]; ++j) {
/* make coefficient positive */
cfs_ff[j] += (cfs_ff[j] >> 31) & fc;
cf32[j-off] = (cf32_t)cfs_ff[j];
cf32[j-off] = (cf32_t)(cfs_ff[j] % fc);
}
sort_terms_ff_32(&(bs->cf_32[ctr]), &(bs->hm[ctr]), ht);
ctr++;
Expand Down
26 changes: 26 additions & 0 deletions test/diff/diff_input-overflow-16.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

file=input-overflow-16


$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res -l 2
if [ $? -gt 0 ]; then
exit 1
fi

diff test/diff/$file.res output_files/$file.res
if [ $? -gt 0 ]; then
exit 2
fi

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res -l 44
if [ $? -gt 0 ]; then
exit 3
fi

diff test/diff/$file.res output_files/$file.res
if [ $? -gt 0 ]; then
exit 4
fi

rm test/diff/$file.res
26 changes: 26 additions & 0 deletions test/diff/diff_input-overflow-8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

file=input-overflow-8


$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res -l 2
if [ $? -gt 0 ]; then
exit 1
fi

diff test/diff/$file.res output_files/$file.res
if [ $? -gt 0 ]; then
exit 2
fi

$(pwd)/msolve -f input_files/$file.ms -o test/diff/$file.res -l 44
if [ $? -gt 0 ]; then
exit 3
fi

diff test/diff/$file.res output_files/$file.res
if [ $? -gt 0 ]; then
exit 4
fi

rm test/diff/$file.res

0 comments on commit e706927

Please sign in to comment.