Skip to content

Commit ce16f73

Browse files
committed
COMMON: Fix LET command problem found in 32bit linux
1 parent cb62e23 commit ce16f73

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2015-08-02
22
Fix display output before DELAY
3+
Fix LET command problem found in 32bit linux
34
Removed obsolete/unimplemented keywords WSPLIT, PLOT2, UNLOADLIB
45

56
2015-07-18

src/common/fmt.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// limits for use with 32bit integer algorithm
2828
#define FMT_xMIN 1e-8 // lowest limit to use the exp. format
2929
#define FMT_xMAX 1e+9 // highest limit to use the exp. format
30-
#define FMT_RND 7 // rounding on x digits
30+
#define FMT_RND 9 // rounding on x digits
3131
#define FMT_xRND 1e+9 // 1 * 10 ^ FMT_RND
3232
#define FMT_xRND2 1e+8 // 1 * 10 ^ (FMT_RND-1)
3333
#endif
@@ -81,14 +81,15 @@ void fptoa(var_num_t x, char *dest) {
8181
}
8282

8383
/*
84-
* remove rightest zeroes from the number
84+
* Convert to text then remove righmost zeroes from the string
8585
*/
86-
var_num_t rmzeros(var_num_t n) {
87-
var_int_t i = fint(n);
88-
while (i > 0 && i % 10 == 0) {
89-
i /= 10;
86+
void fptoa_rmzeros(var_num_t x, char *dest) {
87+
fptoa(x, dest);
88+
int end = strlen(dest);
89+
while (end > 0 && dest[end - 1] == '0') {
90+
end--;
9091
}
91-
return i;
92+
dest[end] = '\0';
9293
}
9394

9495
/*
@@ -192,7 +193,7 @@ void bestfta_p(var_num_t x, char *dest, var_num_t minx, var_num_t maxx) {
192193
*d++ = '0';
193194
}
194195

195-
fptoa(rmzeros(fpart), buf);
196+
fptoa_rmzeros(fpart, buf);
196197
strcpy(d, buf);
197198
d += strlen(buf);
198199
}

src/common/scan.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,20 +2634,30 @@ void comp_text_line(char *text) {
26342634
return;
26352635
}
26362636
}
2637-
if (idx == kwLET) { // old-style keyword LET
2638-
char *p;
2637+
if (idx == kwLET) {
2638+
// old-style keyword LET
26392639
idx = -1;
2640-
p = (char *)comp_next_word(comp_bc_parm, comp_bc_name);
2641-
strcpy(comp_bc_parm, p);
2642-
} else if (idx == kwDECLARE) { // declaration
2643-
char *p;
2640+
char *p = (char *)comp_next_word(comp_bc_parm, comp_bc_name);
2641+
if (p > comp_bc_parm) {
2642+
// p is an offset of comp_bc_parm
2643+
int len = strlen(p);
2644+
memmove(comp_bc_parm, p, len);
2645+
comp_bc_parm[len] = '\0';
2646+
}
2647+
} else if (idx == kwDECLARE) {
2648+
// declaration
26442649
decl = 1;
2645-
p = (char *)comp_next_word(comp_bc_parm, comp_bc_name);
2650+
char *p = (char *)comp_next_word(comp_bc_parm, comp_bc_name);
26462651
idx = comp_is_keyword(comp_bc_name);
26472652
if (idx == -1) {
26482653
idx = comp_is_proc(comp_bc_name);
26492654
}
2650-
strcpy(comp_bc_parm, p);
2655+
if (p > comp_bc_parm) {
2656+
// p is an offset of comp_bc_parm
2657+
int len = strlen(p);
2658+
memmove(comp_bc_parm, p, len);
2659+
comp_bc_parm[len] = '\0';
2660+
}
26512661
if (idx != kwPROC && idx != kwFUNC) {
26522662
sc_raise(MSG_USE_DECL);
26532663
return;

src/common/sys.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,10 @@ typedef unsigned int bcip_t;
4747
#endif
4848

4949
#define DBL_EPSILON 0.00000000000001
50-
#define FLT_EPSILON 0.0000002
51-
52-
#if UINT_MAX != 0xffffffffU
53-
#define OS_PREC64
54-
typedef double var_num_t;
5550
#define EPSILON DBL_EPSILON
56-
#else
57-
typedef float var_num_t;
58-
#define EPSILON FLT_EPSILON
59-
#endif
51+
#define OS_PREC64
6052

53+
typedef double var_num_t;
6154
typedef long int var_int_t;
6255
#define VAR_NUM_FMT "%f"
6356
#define VAR_INT_FMT "%ld"

0 commit comments

Comments
 (0)