~ubuntu-branches/ubuntu/gutsy/bc/gutsy

« back to all changes in this revision

Viewing changes to debian/patch-bug191663

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2004-04-29 20:54:22 UTC
  • Revision ID: james.westby@ubuntu.com-20040429205422-7p6w6hg8d5x5z2tn
Tags: 1.06-15
* configure.in: Patch was supposed to be '-I -8' (Closes: #237957)
* Also ran autoconf2.50 to re-create configure

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>
 
9
 
 
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
 
14
> normal.
 
15
 
16
 
17
> Ken,
 
18
 
19
> Here is a renewed report on dc croaking on some odd input. Would you have
 
20
> any update on this?
 
21
 
 
22
Try this...
 
23
                --Ken Pizzini
 
24
 
 
25
 
 
26
Index: dc/dc-proto.h
 
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
 
33
@@ -1,7 +1,7 @@
 
34
 /*
 
35
  * prototypes of all externally visible dc functions
 
36
  * 
 
37
- * Copyright (C) 1994, 1997, 1998 Free Software Foundation, Inc.
 
38
+ * Copyright (C) 1994, 1997, 1998, 2003 Free Software Foundation, Inc.
 
39
  *
 
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
 
42
@@ -57,7 +57,7 @@
 
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 *));
 
51
Index: dc/dc.c
 
52
===================================================================
 
53
RCS file: /home/phil/CVSroot/bc/dc/dc.c,v
 
54
retrieving revision 1.2
 
55
diff -u -r1.2 dc.c
 
56
--- dc/dc.c     2001/05/13 19:09:31     1.2
 
57
+++ dc/dc.c     2003/05/09 21:51:52
 
58
@@ -1,7 +1,7 @@
 
59
 /* 
 
60
  * implement the "dc" Desk Calculator language.
 
61
  *
 
62
- * Copyright (C) 1994, 1997, 1998, 2000 Free Software Foundation, Inc.
 
63
+ * Copyright (C) 1994, 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
 
64
  *
 
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
 
67
@@ -148,7 +148,7 @@
 
68
                switch (c) {
 
69
                case 'e':
 
70
                        {       dc_data string = dc_makestring(optarg, strlen(optarg));
 
71
-                               if (dc_evalstr(string))
 
72
+                               if (dc_evalstr(&string))
 
73
                                        return EXIT_SUCCESS;
 
74
                                dc_free_str(&string.v.string);
 
75
                                did_eval = 1;
 
76
Index: dc/eval.c
 
77
===================================================================
 
78
RCS file: /home/phil/CVSroot/bc/dc/eval.c,v
 
79
retrieving revision 1.2
 
80
diff -u -r1.2 eval.c
 
81
--- dc/eval.c   2000/07/31 07:29:38     1.2
 
82
+++ dc/eval.c   2003/05/09 21:51:52
 
83
@@ -1,7 +1,7 @@
 
84
 /* 
 
85
  * evaluate the dc language, from a FILE* or a string
 
86
  *
 
87
- * Copyright (C) 1994, 1997, 1998, 2000 Free Software Foundation, Inc.
 
88
+ * Copyright (C) 1994, 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
 
89
  *
 
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
 
92
@@ -55,6 +55,7 @@
 
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' */
 
97
 
 
98
        DC_EOF_ERROR    /* unexpected end of input; abort current eval */
 
99
 } dc_status;
 
100
@@ -116,13 +117,13 @@
 
101
  */
 
102
 static int
 
103
 dc_eval_and_free_str DC_DECLARG((string))
 
104
-       dc_data string DC_DECLEND
 
105
+       dc_data *string DC_DECLEND
 
106
 {
 
107
        dc_status status;
 
108
 
 
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);
 
114
        return status;
 
115
 }
 
116
 
 
117
@@ -207,9 +208,7 @@
 
118
                if (peekc == EOF)
 
119
                        return DC_EOF_ERROR;
 
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)
 
123
-                                       return DC_QUIT;
 
124
+                       return DC_EVALREG;
 
125
                return DC_EATONE;
 
126
        case '=':
 
127
                /* eval register named by peekc if
 
128
@@ -218,9 +217,7 @@
 
129
                if (peekc == EOF)
 
130
                        return DC_EOF_ERROR;
 
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)
 
134
-                                       return DC_QUIT;
 
135
+                       return DC_EVALREG;
 
136
                return DC_EATONE;
 
137
        case '>':
 
138
                /* eval register named by peekc if
 
139
@@ -229,16 +226,15 @@
 
140
                if (peekc == EOF)
 
141
                        return DC_EOF_ERROR;
 
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)
 
145
-                                       return DC_QUIT;
 
146
+                       return DC_EVALREG;
 
147
                return DC_EATONE;
 
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;
 
152
                }
 
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)
 
156
                        return DC_QUIT;
 
157
                return DC_OKAY;
 
158
        case '[':       /* read to balancing ']' into a dc_str */
 
159
@@ -341,7 +337,7 @@
 
160
                return DC_QUIT;
 
161
        case 'r':       /* rotate (swap) the top two elements on the stack
 
162
                                 */
 
163
-               if (dc_pop(&datum) == DC_SUCCESS) {
 
164
+               if (dc_pop(&datum) == DC_SUCCESS){
 
165
                        dc_data datum2;
 
166
                        int two_status;
 
167
                        two_status = dc_pop(&datum2);
 
168
@@ -376,7 +372,7 @@
 
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)
 
174
                                        return DC_QUIT;
 
175
                        }else if (datum.dc_type == DC_NUMBER){
 
176
                                dc_push(datum);
 
177
@@ -520,7 +516,7 @@
 
178
 /* takes a string and evals it */
 
179
 int
 
180
 dc_evalstr DC_DECLARG((string))
 
181
-       dc_data string DC_DECLEND
 
182
+       dc_data *string DC_DECLEND
 
183
 {
 
184
        const char *s;
 
185
        const char *end;
 
186
@@ -531,15 +527,16 @@
 
187
        int count;
 
188
        int negcmp;
 
189
        int next_negcmp = 0;
 
190
+       int tail_depth = 1; /* how much tail recursion is active */
 
191
 
 
192
-       if (string.dc_type != DC_STRING){
 
193
+       if (string->dc_type != DC_STRING){
 
194
                fprintf(stderr,
 
195
                                "%s: eval called with non-string argument\n",
 
196
                                progname);
 
197
                return DC_OKAY;
 
198
        }
 
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);
 
203
        while (s < end){
 
204
                c = *(const unsigned char *)s++;
 
205
                peekc = EOF;
 
206
@@ -555,8 +552,8 @@
 
207
                                ++s;
 
208
                        break;
 
209
                case DC_QUIT:
 
210
-                       if (unwind_depth > 0){
 
211
-                               --unwind_depth;
 
212
+                       if (unwind_depth >= tail_depth){
 
213
+                               unwind_depth -= tail_depth;
 
214
                                return DC_QUIT;
 
215
                        }
 
216
                        return DC_OKAY;
 
217
@@ -591,6 +588,36 @@
 
218
                case DC_NEGCMP:
 
219
                        next_negcmp = 1;
 
220
                        break;
 
221
+               case DC_EVALREG:
 
222
+                       if (peekc == EOF){
 
223
+                               fprintf(stderr, "%s: unexpected EOS\n", progname);
 
224
+                               return DC_OKAY;
 
225
+                       }else{
 
226
+                               dc_data evalstr;
 
227
+                               ++s;
 
228
+                               if (dc_register_get(peekc, &evalstr) == DC_SUCCESS){
 
229
+                                       if (s == end){
 
230
+                                               if (evalstr.dc_type != DC_STRING){
 
231
+                                                       fprintf(stderr,
 
232
+                                                               "%s: eval called with non-string argument\n",
 
233
+                                                               progname);
 
234
+                                                       return DC_OKAY;
 
235
+                                               }
 
236
+                                               dc_free_str(&string->v.string);
 
237
+                                               *string = evalstr;
 
238
+                                               s = dc_str2charp(string->v.string);
 
239
+                                               end = s + dc_strlen(string->v.string);
 
240
+                                               ++tail_depth;
 
241
+                                       }else if (dc_eval_and_free_str(&evalstr) == DC_QUIT){
 
242
+                                               if (unwind_depth > 0){
 
243
+                                                       --unwind_depth;
 
244
+                                                       return DC_QUIT;
 
245
+                                               }
 
246
+                                               return DC_OKAY;
 
247
+                                       }
 
248
+                               }
 
249
+                       }
 
250
+                       break;
 
251
 
 
252
                case DC_EOF_ERROR:
 
253
                        fprintf(stderr, "%s: unexpected EOS\n", progname);
 
254
@@ -672,6 +699,19 @@
 
255
                case DC_NEGCMP:
 
256
                        next_negcmp = 1;
 
257
                        break;
 
258
+               case DC_EVALREG:
 
259
+                       {
 
260
+                               dc_data evalstr;
 
261
+                               c = peekc;
 
262
+                               peekc = getc(fp);
 
263
+                               if (dc_register_get(c, &evalstr) == DC_SUCCESS &&
 
264
+                                                       dc_eval_and_free_str(&evalstr) == DC_QUIT){
 
265
+                                       if (unwind_noexit != DC_TRUE)
 
266
+                                               return DC_SUCCESS;
 
267
+                                       fprintf(stderr, "%s: Q command argument exceeded string execution depth\n", progname);
 
268
+                               }
 
269
+                       }
 
270
+                       break;
 
271
 
 
272
                case DC_EOF_ERROR:
 
273
                        fprintf(stderr, "%s: unexpected EOF\n", progname);
 
274
@@ -680,3 +720,12 @@
 
275
        }
 
276
        return DC_SUCCESS;
 
277
 }
 
278
+
 
279
+
 
280
+/*
 
281
+  ! Local Variables: !
 
282
+  ! mode: C !
 
283
+  ! tab-width: 4 !
 
284
+  ! End: !
 
285
+  vi: ts=4 sw=4
 
286
+*/
 
287
 
 
288