Skip to content

Commit c53736b

Browse files
authored
Merge branch 'smallbasic:master' into 12_27
2 parents a0056ae + 14fc195 commit c53736b

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

samples/distro-examples/tests/all.bas

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ print "DETERM:"' + DETERM (A, 1)
140140
print "DISCLOSE:" + DISCLOSE("{debraceme}", "{}")
141141
print "ENCLOSE:" + ENCLOSE ("braceme", "{}")
142142
print "EOF:"' + EOF (fileN)
143-
print "EXIST:"' + EXIST (file)
143+
print "EXIST:" + EXIST ("Makefile")
144144
print "EXP:" + EXP (x)
145145
print "FILES:"; FILES ("file-not-found")
146146
print "FIX:" + FIX (x)
@@ -245,3 +245,5 @@ print "VAL:" + VAL (s)
245245
print "WEEKDAY:" + WEEKDAY(dmy) + " " + WEEKDAY(1,1,2020) + " " + WEEKDAY(JULIAN(d,m,y))
246246
print "XPOS:" + XPOS
247247
print "YPOS:" + YPOS
248+
print "RoundPrecisionBug:"; 32.99999999999999
249+
print "RoundPrecisionBug2:"; 64.1

samples/distro-examples/tests/output/all.out

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ DETERM:
123123
DISCLOSE:debraceme
124124
ENCLOSE:{braceme}
125125
EOF:
126-
EXIST:
126+
EXIST:1
127127
EXP:219695.9886721379
128128
FILES:[]
129129
FIX:13
@@ -228,3 +228,5 @@ VAL:0
228228
WEEKDAY:-1 3 1
229229
XPOS:0
230230
YPOS:0
231+
RoundPrecisionBug:33
232+
RoundPrecisionBug2:64.1

samples/distro-examples/tests/strings.bas

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,9 @@ for t in number_test
209209
if (t[1] != bin(t[0])) then throw "err: bin(" + str(t[0]) + ") <> " + t[1]
210210
if (t[2] != oct(t[0])) then throw "err: oct(" + str(t[0]) + ") <> " + t[2]
211211
if (t[3] != hex(t[0])) then throw "err: hex(" + str(t[0]) + ") <> " + t[3]
212-
next
212+
next
213+
214+
REM Bug: RTRIM trimed input string on the right side
215+
s1 = " test "
216+
s2 = rtrim(s1)
217+
if(s1 != " test ") then throw "err: RTRIM changed input string"

src/common/blib_func.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,19 +1050,17 @@ void cmd_str1(long funcCode, var_t *arg, var_t *r) {
10501050
break;
10511051
}
10521052
p = arg->v.p.ptr;
1053+
uint32_t len = strlen(arg->v.p.ptr);
10531054
if (*p != '\0') {
1054-
while (*p) {
1055-
p++;
1056-
}
1057-
p--;
1058-
while (p >= arg->v.p.ptr && (is_wspace(*p))) {
1055+
p = p + len - 1;
1056+
while (p >= arg->v.p.ptr && is_wspace(*p)) {
1057+
len--;
10591058
p--;
10601059
}
1061-
p++;
1062-
*p = '\0';
10631060
}
1064-
r->v.p.ptr = (char *)malloc(strlen(arg->v.p.ptr) + 1);
1065-
strcpy(r->v.p.ptr, arg->v.p.ptr);
1061+
r->v.p.ptr = (char *)malloc(len + 1);
1062+
strncpy(r->v.p.ptr, arg->v.p.ptr, len);
1063+
r->v.p.ptr[len] = '\0';
10661064
r->v.p.length = strlen(r->v.p.ptr) + 1;
10671065

10681066
// alltrim

src/common/blib_math.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void mat_gauss_jordan(var_num_t *a, var_num_t *b, int n, double toler) {
121121
indxr[i] = irow;
122122
indxc[i] = icol;
123123

124-
if (a[icol * n + icol] < toler) {
124+
if (fabs(a[icol * n + icol]) < toler) {
125125
err_matsig();
126126
free(indxc);
127127
free(indxr);

src/common/fmt.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@
2020
#define FMT_xMIN 1e-8
2121
#define FMT_xMAX 1e+14
2222
#define FMT_RND 14
23-
#define FMT_xRND 1e+14
24-
#define FMT_xRND2 1e+13
2523
#define FMT_MANTISSA_BITS 52
2624
#else
2725
// limits for use with 32bit integer algorithm
2826
#define FMT_xMIN 1e-8 // lowest limit to use the exp. format
2927
#define FMT_xMAX 1e+9 // highest limit to use the exp. format
3028
#define FMT_RND 9 // rounding on x digits
31-
#define FMT_xRND 1e+9 // 1 * 10 ^ FMT_RND
32-
#define FMT_xRND2 1e+8 // 1 * 10 ^ (FMT_RND-1)
3329
#define FMT_MANTISSA_BITS 23 // Bits of mantissa for 32bit float
3430
#endif
3531

@@ -183,7 +179,7 @@ void bestfta_p(var_num_t x, char *dest, var_num_t minx, var_num_t maxx) {
183179
}
184180
fpart = fround(frac(x), precision) * pow(10, precision);
185181

186-
if (fpart >= FMT_xRND) { // rounding bug
182+
if (fpart >= pow(10, precision)) { // rounding bug, i.e: print 32.99999999999999 -> Output: 32.1
187183
ipart = ipart + 1.0;
188184
if (ipart >= maxx) {
189185
ipart = ipart / 10.0;
@@ -195,18 +191,13 @@ void bestfta_p(var_num_t x, char *dest, var_num_t minx, var_num_t maxx) {
195191
fptoa(ipart, buf);
196192
strcpy(d, buf);
197193
d += strlen(buf);
198-
194+
199195
if (fpart > 0.0) {
200196
// format right part
201197
*d++ = '.';
198+
fdif = fpart;
202199

203-
fdif = frac(x) * FMT_xRND;
204-
if (fdif < fpart) {
205-
// rounded value has greater precision
206-
fdif = fpart;
207-
}
208-
209-
while (fdif < FMT_xRND2) {
200+
while (fdif < pow(10, precision - 1)) {
210201
fdif *= 10;
211202
*d++ = '0';
212203
}

src/platform/console/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ int main(int argc, char *argv[]) {
449449
return gsb_last_error ? gsb_last_line : 0;
450450
}
451451

452-
#if defined(__GNUC__) && !defined(__MACH__) && !defined(_Win32)
452+
#if defined(__GNUC__) && !defined(__MACH__) && !defined(_Win32) && !defined(__CYGWIN__)
453453
// for analysing excessive malloc calls using kdbg
454454
extern "C" void *__libc_malloc(size_t size);
455455
void *malloc(size_t size) {

0 commit comments

Comments
 (0)