Skip to content

Instantly share code, notes, and snippets.

@fivepiece
Created March 9, 2018 19:03
Show Gist options
  • Save fivepiece/51b9bfa7b7b1e9fe8944219adfbce405 to your computer and use it in GitHub Desktop.
Save fivepiece/51b9bfa7b7b1e9fe8944219adfbce405 to your computer and use it in GitHub Desktop.
gnu bc non base 10 array index segfault
#!/usr/bin/bc
# bc has memory issues
# this program will cause bc 1.07.1, 1.06.95, to segfault
define void toucharr(num, *ret[]){
ret[0] = num;
}
define void fillarrs(){
toucharr(06, aaa[]); print "aaa[0] = ", aaa[0], "\n";
toucharr(07, bbb[]); print "bbb[0] = ", bbb[0], "\n";
toucharr(08, ccc[]); print "ccc[0] = ", ccc[0], "\n";
toucharr(09, ddd[]); print "ddd[0] = ", ddd[0], "\n";
toucharr(10, eee[]); print "eee[0] = ", eee[0], "\n";
toucharr(11, fff[]); print "fff[0] = ", fff[0], "\n";
toucharr(12, ggg[]); print "ggg[0] = ", ggg[0], "\n";
toucharr(13, hhh[]); print "hhh[0] = ", hhh[0], "\n";
toucharr(14, iii[]); print "iii[0] = ", iii[0], "\n";
toucharr(15, jjj[]); print "jjj[0] = ", jjj[0], "\n";
toucharr(16, kkk[]); print "kkk[0] = ", kkk[0], "\n";
toucharr(17, lll[]); print "lll[0] = ", lll[0], "\n";
toucharr(18, mmm[]); print "mmm[0] = ", mmm[0], "\n";
toucharr(19, nnn[]); print "nnn[0] = ", nnn[0], "\n";
toucharr(20, ooo[]); print "ooo[0] = ", ooo[0], "\n";
toucharr(21, ppp[]); print "ppp[0] = ", ppp[0], "\n";
toucharr(22, qqq[]); print "qqq[0] = ", qqq[0], "\n";
toucharr(23, rrr[]); print "rrr[0] = ", rrr[0], "\n";
toucharr(24, sss[]); print "sss[0] = ", sss[0], "\n";
toucharr(25, ttt[]); print "ttt[0] = ", ttt[0], "\n";
toucharr(26, uuu[]); print "uuu[0] = ", uuu[0], "\n";
toucharr(27, vvv[]); print "vvv[0] = ", vvv[0], "\n";
toucharr(28, www[]); print "www[0] = ", www[0], "\n";
toucharr(29, xxx[]); print "xxx[0] = ", xxx[0], "\n";
toucharr(30, yyy[]); print "yyy[0] = ", yyy[0], "\n";
toucharr(31, zzz[]); print "zzz[0] = ", zzz[0], "\n";
}
# this one behaves as expected
define void fillarr_b10() {
print "\nfillarr_b10() : \n";
fillarrs();
}
####
# this doesn't segfaults, but values are not the same
define void fillarr_b8() {
obase = 8;
ibase = 8;
print "\nfillarr_b8() : \n";
fillarrs();
}
####
# these will segfault on different arrays. commenting an array in fillarrs()
# will let the segfaulting run advance forward one more array, and numbers in
# arr[0] are not always the same.
# will segfault in zzz[]
define void fillarr_b13() {
obase = 13;
ibase = 13;
print "\nfillarr_b13() : \n";
fillarrs();
}
# will segfault in xxx[]
define void fillarr_b14() {
obase = 14;
ibase = 14;
print "\nfillarr_b14() : \n";
fillarrs();
}
# will segfault in vvv[]
define void fillarr_b15() {
obase = 15;
ibase = 15;
print "\nfillarr_b15() : \n";
fillarrs();
}
# will segfault in ttt[]
define void fillarr_b16() {
obase = 16;
ibase = 16;
print "\nfillarr_b16() : \n";
fillarrs();
}
####
# this one is just to reset ibase, obase values for the next run
define void reset_base() {
obase=A;
ibase=A;
}
fillarr_b10()
reset_base()
#fillarr_b8()
#reset_base()
#fillarr_b13()
#reset_base()
#fillarr_b14()
#reset_base()
#fillarr_b15()
#reset_base()
fillarr_b16()
reset_base()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment