1
Date: Fri, 9 May 2003 14:58:23 -0700
2
From: Ken Pizzini <ken@gnu.org>
3
To: Dirk Eddelbuettel <edd@debian.org>
4
Cc: "Brian M. Carlson" <sandals@crustytoothpaste.ath.cx>,
5
control@bugs.debian.org
6
Subject: Re: Bug#191663: dc: kills itself when trying to factor large numbers
7
Message-ID: <20030509215823.GA2801@holly2.wcg>
8
In-Reply-To: <20030502174822.GA9175@sonny.eddelbuettel.com>
10
On Fri, May 02, 2003 at 12:48:22PM -0500, Dirk Eddelbuettel wrote:
11
> Thanks for the bugreport. It turns out that we already had the same issue
12
> reported once before as #135029. In order to merge the two, I had to adjust
13
> the severity. Given that dc behaves ok under normal input, I set this to
19
> Here is a renewed report on dc croaking on some odd input. Would you have
27
===================================================================
28
RCS file: /home/phil/CVSroot/bc/dc/dc-proto.h,v
29
retrieving revision 1.2
30
diff -u -r1.2 dc-proto.h
31
--- dc/dc-proto.h 2000/09/13 18:43:04 1.2
32
+++ dc/dc-proto.h 2003/05/09 21:51:52
35
* prototypes of all externally visible dc functions
37
- * Copyright (C) 1994, 1997, 1998 Free Software Foundation, Inc.
38
+ * Copyright (C) 1994, 1997, 1998, 2003 Free Software Foundation, Inc.
40
* This program is free software; you can redistribute it and/or modify
41
* it under the terms of the GNU General Public License as published by
43
extern int dc_cmpop DC_PROTO((void));
44
extern int dc_compare DC_PROTO((dc_num, dc_num));
45
extern int dc_evalfile DC_PROTO((FILE *));
46
-extern int dc_evalstr DC_PROTO((dc_data));
47
+extern int dc_evalstr DC_PROTO((dc_data *));
48
extern int dc_num2int DC_PROTO((dc_num, dc_discard));
49
extern int dc_numlen DC_PROTO((dc_num));
50
extern int dc_pop DC_PROTO((dc_data *));
52
===================================================================
53
RCS file: /home/phil/CVSroot/bc/dc/dc.c,v
54
retrieving revision 1.2
56
--- dc/dc.c 2001/05/13 19:09:31 1.2
57
+++ dc/dc.c 2003/05/09 21:51:52
60
* implement the "dc" Desk Calculator language.
62
- * Copyright (C) 1994, 1997, 1998, 2000 Free Software Foundation, Inc.
63
+ * Copyright (C) 1994, 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
65
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
70
{ dc_data string = dc_makestring(optarg, strlen(optarg));
71
- if (dc_evalstr(string))
72
+ if (dc_evalstr(&string))
74
dc_free_str(&string.v.string);
77
===================================================================
78
RCS file: /home/phil/CVSroot/bc/dc/eval.c,v
79
retrieving revision 1.2
81
--- dc/eval.c 2000/07/31 07:29:38 1.2
82
+++ dc/eval.c 2003/05/09 21:51:52
85
* evaluate the dc language, from a FILE* or a string
87
- * Copyright (C) 1994, 1997, 1998, 2000 Free Software Foundation, Inc.
88
+ * Copyright (C) 1994, 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
90
* This program is free software; you can redistribute it and/or modify
91
* it under the terms of the GNU General Public License as published by
93
DC_SYSTEM, /* caller needs to run a system() on next input line */
94
DC_COMMENT, /* caller needs to skip to the next input line */
95
DC_NEGCMP, /* caller needs to re-call dc_func() with `negcmp' set */
96
+ DC_EVALREG, /* caller needs to eval the string named by `peekc' */
98
DC_EOF_ERROR /* unexpected end of input; abort current eval */
100
@@ -116,13 +117,13 @@
103
dc_eval_and_free_str DC_DECLARG((string))
104
- dc_data string DC_DECLEND
105
+ dc_data *string DC_DECLEND
109
status = dc_evalstr(string);
110
- if (string.dc_type == DC_STRING)
111
- dc_free_str(&string.v.string);
112
+ if (string->dc_type == DC_STRING)
113
+ dc_free_str(&string->v.string);
120
if ( (dc_cmpop() < 0) == !negcmp )
121
- if (dc_register_get(peekc, &datum) == DC_SUCCESS)
122
- if (dc_eval_and_free_str(datum) == DC_QUIT)
127
/* eval register named by peekc if
131
if ( (dc_cmpop() == 0) == !negcmp )
132
- if (dc_register_get(peekc, &datum) == DC_SUCCESS)
133
- if (dc_eval_and_free_str(datum) == DC_QUIT)
138
/* eval register named by peekc if
139
@@ -229,16 +226,15 @@
142
if ( (dc_cmpop() > 0) == !negcmp )
143
- if (dc_register_get(peekc, &datum) == DC_SUCCESS)
144
- if (dc_eval_and_free_str(datum) == DC_QUIT)
148
case '?': /* read a line from standard-input and eval it */
149
if (stdin_lookahead != EOF){
150
ungetc(stdin_lookahead, stdin);
151
stdin_lookahead = EOF;
153
- if (dc_eval_and_free_str(dc_readstring(stdin, '\n', '\n')) == DC_QUIT)
154
+ datum = dc_readstring(stdin, '\n', '\n');
155
+ if (dc_eval_and_free_str(&datum) == DC_QUIT)
158
case '[': /* read to balancing ']' into a dc_str */
161
case 'r': /* rotate (swap) the top two elements on the stack
163
- if (dc_pop(&datum) == DC_SUCCESS) {
164
+ if (dc_pop(&datum) == DC_SUCCESS){
167
two_status = dc_pop(&datum2);
169
case 'x': /* eval the datum popped from top of stack */
170
if (dc_pop(&datum) == DC_SUCCESS){
171
if (datum.dc_type == DC_STRING){
172
- if (dc_eval_and_free_str(datum) == DC_QUIT)
173
+ if (dc_eval_and_free_str(&datum) == DC_QUIT)
175
}else if (datum.dc_type == DC_NUMBER){
178
/* takes a string and evals it */
180
dc_evalstr DC_DECLARG((string))
181
- dc_data string DC_DECLEND
182
+ dc_data *string DC_DECLEND
186
@@ -531,15 +527,16 @@
190
+ int tail_depth = 1; /* how much tail recursion is active */
192
- if (string.dc_type != DC_STRING){
193
+ if (string->dc_type != DC_STRING){
195
"%s: eval called with non-string argument\n",
199
- s = dc_str2charp(string.v.string);
200
- end = s + dc_strlen(string.v.string);
201
+ s = dc_str2charp(string->v.string);
202
+ end = s + dc_strlen(string->v.string);
204
c = *(const unsigned char *)s++;
210
- if (unwind_depth > 0){
212
+ if (unwind_depth >= tail_depth){
213
+ unwind_depth -= tail_depth;
223
+ fprintf(stderr, "%s: unexpected EOS\n", progname);
228
+ if (dc_register_get(peekc, &evalstr) == DC_SUCCESS){
230
+ if (evalstr.dc_type != DC_STRING){
232
+ "%s: eval called with non-string argument\n",
236
+ dc_free_str(&string->v.string);
238
+ s = dc_str2charp(string->v.string);
239
+ end = s + dc_strlen(string->v.string);
241
+ }else if (dc_eval_and_free_str(&evalstr) == DC_QUIT){
242
+ if (unwind_depth > 0){
253
fprintf(stderr, "%s: unexpected EOS\n", progname);
263
+ if (dc_register_get(c, &evalstr) == DC_SUCCESS &&
264
+ dc_eval_and_free_str(&evalstr) == DC_QUIT){
265
+ if (unwind_noexit != DC_TRUE)
267
+ fprintf(stderr, "%s: Q command argument exceeded string execution depth\n", progname);
273
fprintf(stderr, "%s: unexpected EOF\n", progname);
281
+ ! Local Variables: !