Package: dc
Version: 1.06.94-3
Severity: normal
Tags: patch
User: [EMAIL PROTECTED]
Usertags: origin-ubuntu intrepid ubuntu-patch

Hi,

The attached patch by Ian Jackson is used in Ubuntu to make
dc notice errors on its input and output. Please consider
applying it.

Thanks,

James

+bc (1.06-19ubuntu1) dapper; urgency=low
+
+  * Make dc notice read and write errors on its input and output.
+    I grepped for mentions of the strings `putc', `print', `getc', `FILE',
+    `stdin', `stdout' and `stderr' and added calls to new error-checking
+    functions unless it was clear from the immediately-surrounding code
+    that the program was exiting nonzero, or would exit nonzero if the
+    call failed.  I ignored hits in lib/getopt*, which seems to
+    pervasively ignore write errors when printing usage messages, in the
+    hope that these were correct.  I _think_ I got them all.  -iwj.
+
+ -- Ian Jackson <[EMAIL PROTECTED]>  Tue,  4 Apr 2006 17:21:02 +0100
+

diff -pruN 1.06.94-3/bc/execute.c 1.06.94-3ubuntu1/bc/execute.c
--- 1.06.94-3/bc/execute.c	2006-06-09 18:04:31.000000000 +0100
+++ 1.06.94-3ubuntu1/bc/execute.c	2007-12-05 13:11:11.000000000 +0000
@@ -108,6 +108,7 @@ execute ()
 	      }
 	    out_char ('\n');
 	  }
+	checkferror_output(stdout);
       }
 #endif
 
@@ -222,6 +223,7 @@ execute ()
 		}
 	    }
 	fflush (stdout);
+	checkferror_output(stdout);
 	break;
 
       case 'R' : /* Return from function */
@@ -257,6 +259,7 @@ execute ()
 	if (inst == 'W') out_char ('\n');
 	store_var (4);  /* Special variable "last". */
 	fflush (stdout);
+	checkferror_output(stdout);
 	pop ();
 	break;
 
@@ -338,6 +341,7 @@ execute ()
       case 'w' : /* Write a string to the output. */
 	while ((ch = byte(&pc)) != '"') out_schar (ch);
 	fflush (stdout);
+	checkferror_output(stdout);
 	break;
 		   
       case 'x' : /* Exchange Top of Stack with the one under the tos. */
@@ -545,7 +549,10 @@ execute ()
     {
       signal (SIGINT, use_quit);
       if (had_sigint)
-	printf ("\ninterrupted execution.\n");
+	{
+	  printf ("\ninterrupted execution.\n");
+	  checkferror_output(stdout);
+	}
     }
 }
 
@@ -580,6 +587,7 @@ input_char ()
 	  out_col = 0;  /* Saw a new line */
 	}
     }
+  checkferror_input(stdin);
 
   /* Classify and preprocess the input character. */
   if (isdigit(in_ch))
diff -pruN 1.06.94-3/bc/load.c 1.06.94-3ubuntu1/bc/load.c
--- 1.06.94-3/bc/load.c	2006-06-09 18:04:31.000000000 +0100
+++ 1.06.94-3ubuntu1/bc/load.c	2007-12-05 13:11:11.000000000 +0000
@@ -217,6 +217,7 @@ load_code (code)
 		if (label_no > 65535L)
 		  {  /* Better message? */
 		    fprintf (stderr,"Program too big.\n");
+		    checkferror_output(stderr);
 		    exit(1);
 		  }
 		addbyte ( (char) (label_no & 0xFF));
diff -pruN 1.06.94-3/bc/sbc.y 1.06.94-3ubuntu1/bc/sbc.y
--- 1.06.94-3/bc/sbc.y	2005-05-27 08:48:32.000000000 +0100
+++ 1.06.94-3ubuntu1/bc/sbc.y	2007-12-05 13:11:11.000000000 +0000
@@ -86,7 +86,9 @@ program			: /* empty */
 			      if (interactive && !quiet)
 				{
 				  show_bc_version ();
+				  checkferror_output(stdout);
 				  welcome ();
+				  checkferror_output(stdout);
 				}
 			    }
 			| program input_item
diff -pruN 1.06.94-3/bc/scan.c 1.06.94-3ubuntu1/bc/scan.c
--- 1.06.94-3/bc/scan.c	2006-06-09 18:05:10.000000000 +0100
+++ 1.06.94-3ubuntu1/bc/scan.c	2007-12-05 13:11:11.000000000 +0000
@@ -799,6 +799,7 @@ bcel_input (buf, result, max)
       if (bcel_len != 0)
 	history (hist, &histev, H_ENTER, bcel_line); 
       fflush (stdout);
+      checkferror_output(stdout);
     }
 
   if (bcel_len <= max)
@@ -874,6 +875,7 @@ rl_input (buf, result, max)
 	add_history (rl_line); 
       rl_line[rl_len-1] = '\n';
       fflush (stdout);
+      checkferror_output(stdout);
     }
 
   if (rl_len <= max)
diff -pruN 1.06.94-3/bc/scan.l 1.06.94-3ubuntu1/bc/scan.l
--- 1.06.94-3/bc/scan.l	2006-06-09 18:04:31.000000000 +0100
+++ 1.06.94-3ubuntu1/bc/scan.l	2007-12-05 13:11:11.000000000 +0000
@@ -111,6 +111,7 @@ bcel_input (buf, result, max)
       if (bcel_len != 0)
 	history (hist, &histev, H_ENTER, bcel_line); 
       fflush (stdout);
+      checkferror_output(stdout);
     }
 
   if (bcel_len <= max)
@@ -186,6 +187,7 @@ rl_input (buf, result, max)
 	add_history (rl_line); 
       rl_line[rl_len-1] = '\n';
       fflush (stdout);
+      checkferror_output(stdout);
     }
 
   if (rl_len <= max)
@@ -310,6 +312,7 @@ limits return(Limits);
 	    if (c == EOF)
 	      {
 		fprintf (stderr,"EOF encountered in a comment.\n");
+                checkferror_output(stderr);
 		break;
 	      }
 	  }
diff -pruN 1.06.94-3/bc/util.c 1.06.94-3ubuntu1/bc/util.c
--- 1.06.94-3/bc/util.c	2006-06-09 18:04:31.000000000 +0100
+++ 1.06.94-3ubuntu1/bc/util.c	2007-12-05 13:11:11.000000000 +0000
@@ -260,9 +260,10 @@ init_gen ()
   continue_label = 0;
   next_label  = 1;
   out_count = 2;
-  if (compile_only) 
+  if (compile_only) {
     printf ("@i");
-  else
+    checkferror_output(stdout);
+  } else
     init_load ();
   had_error = FALSE;
   did_gen = FALSE;
@@ -286,6 +287,7 @@ generate (str)
 	  printf ("\n");
 	  out_count = 0;
 	}
+      checkferror_output(stdout);
     }
   else
     load_code (str);
@@ -303,6 +305,7 @@ run_code()
       if (compile_only)
 	{
 	  printf ("@r\n"); 
+	  checkferror_output(stdout);
 	  out_count = 0;
 	}
       else
@@ -341,6 +344,7 @@ out_char (ch)
 	}
       putchar (ch);
     }
+  checkferror_output(stdout);
 }
 
 /* Output routines: Write a character CH to the standard output.
@@ -371,6 +375,7 @@ out_schar (ch)
 	}
       putchar (ch);
     }
+  checkferror_output(stdout);
 }
 
 
@@ -656,6 +661,7 @@ limits()
 #ifdef OLD_EQ_OP
   printf ("Old assignment operatiors are valid. (=-, =+, ...)\n");
 #endif 
+  checkferror_output(stdout);
 }
 
 /* bc_malloc will check the return value so all other places do not
@@ -720,6 +726,7 @@ yyerror (str, va_alist)
   fprintf (stderr,"%s %d: ",name,line_no);
   vfprintf (stderr, str, args);
   fprintf (stderr, "\n");
+  checkferror_output(stderr);
   had_error = TRUE;
   va_end (args);
 }
@@ -760,6 +767,7 @@ warn (mesg, va_alist)
       fprintf (stderr,"%s %d: Error: ",name,line_no);
       vfprintf (stderr, mesg, args);
       fprintf (stderr, "\n");
+      checkferror_output(stderr);
       had_error = TRUE;
     }
   else
@@ -772,6 +780,7 @@ warn (mesg, va_alist)
 	fprintf (stderr,"%s %d: (Warning) ",name,line_no);
 	vfprintf (stderr, mesg, args);
 	fprintf (stderr, "\n");
+	checkferror_output(stderr);
       }
   va_end (args);
 }
@@ -806,6 +815,7 @@ rt_error (mesg, va_alist)
   va_end (args);
   
   fprintf (stderr, "\n");
+  checkferror_output(stderr);
   runtime_error = TRUE;
 }
 
@@ -842,4 +852,5 @@ rt_warn (mesg, va_alist)
   va_end (args);
 
   fprintf (stderr, "\n");
+  checkferror_output(stderr);
 }
diff -pruN 1.06.94-3/dc/dc.c 1.06.94-3ubuntu1/dc/dc.c
--- 1.06.94-3/dc/dc.c	2006-06-04 22:05:48.000000000 +0100
+++ 1.06.94-3ubuntu1/dc/dc.c	2007-12-05 13:11:11.000000000 +0000
@@ -61,6 +61,7 @@ static void
 bug_report_info DC_DECLVOID()
 {
 	printf("Email bug reports to:  [EMAIL PROTECTED] .\n");
+	checkferror_output(stdout);
 }
 
 static void
@@ -71,6 +72,7 @@ show_version DC_DECLVOID()
 This is free software; see the source for copying conditions.  There is NO\n\
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,\n\
 to the extent permitted by law.\n", DC_COPYRIGHT);
+	checkferror_output(stdout);
 }
 
 /* your generic usage function */
@@ -87,6 +89,7 @@ Usage: %s [OPTION] [file ...]\n\
 \n\
 ", progname);
 	bug_report_info();
+	checkferror_output(f);
 }
 
 /* returns a pointer to one past the last occurance of c in s,
diff -pruN 1.06.94-3/dc/eval.c 1.06.94-3ubuntu1/dc/eval.c
--- 1.06.94-3/dc/eval.c	2006-06-04 12:04:40.000000000 +0100
+++ 1.06.94-3ubuntu1/dc/eval.c	2007-12-05 13:11:11.000000000 +0000
@@ -94,12 +94,15 @@ static int input_pushback;
 static int
 input_fil DC_DECLVOID()
 {
+        int c;
 	if (input_pushback != EOF){
-		int c = input_pushback;
+		c = input_pushback;
 		input_pushback = EOF;
 		return c;
 	}
-	return getc(input_fil_fp);
+	c = getc(input_fil_fp);
+	checkferror_input(input_fil_fp);
+	return c;
 }
 
 /* passed as an argument to dc_getnum */
@@ -298,11 +301,13 @@ dc_func DC_DECLARG((c, peekc, negcmp))
 				tmpint = dc_num2int(datum.v.number, DC_TOSS);
 			if (2 <= tmpint  &&  tmpint <= DC_IBASE_MAX)
 				dc_ibase = tmpint;
-			else
+			else {
 				fprintf(stderr,
 						"%s: input base must be a number \
 between 2 and %d (inclusive)\n",
 						progname, DC_IBASE_MAX);
+				checkferror_output(stderr);
+			}
 		}
 		break;
 	case 'k':	/* set scale to value on top of stack */
@@ -310,11 +315,12 @@ between 2 and %d (inclusive)\n",
 			tmpint = -1;
 			if (datum.dc_type == DC_NUMBER)
 				tmpint = dc_num2int(datum.v.number, DC_TOSS);
-			if ( ! (tmpint >= 0) )
+			if ( ! (tmpint >= 0) ) {
 				fprintf(stderr,
 						"%s: scale must be a nonnegative number\n",
 						progname);
-			else
+				checkferror_output(stderr);
+			} else
 				dc_scale = tmpint;
 		}
 		break;
@@ -338,11 +344,12 @@ between 2 and %d (inclusive)\n",
 			tmpint = 0;
 			if (datum.dc_type == DC_NUMBER)
 				tmpint = dc_num2int(datum.v.number, DC_TOSS);
-			if ( ! (tmpint > 1) )
+			if ( ! (tmpint > 1) ) {
 				fprintf(stderr,
 						"%s: output base must be a number greater than 1\n",
 						progname);
-			else
+				checkferror_output(stderr);
+			} else
 				dc_obase = tmpint;
 		}
 		break;
@@ -383,6 +390,7 @@ between 2 and %d (inclusive)\n",
 				fprintf(stderr,
 						"%s: square root of nonnumeric attempted\n",
 						progname);
+				checkferror_output(stderr);
 			}else if (dc_sqrt(datum.v.number, dc_scale, &tmpnum) == DC_SUCCESS){
 				dc_free_num(&datum.v.number);
 				datum.v.number = tmpnum;
@@ -444,6 +452,7 @@ between 2 and %d (inclusive)\n",
 			fprintf(stderr,
 					"%s: Q command requires a number >= 1\n",
 					progname);
+			checkferror_output(stderr);
 		}
 		break;
 #if 0
@@ -489,11 +498,12 @@ between 2 and %d (inclusive)\n",
 			if (datum.dc_type == DC_NUMBER)
 				tmpint = dc_num2int(datum.v.number, DC_TOSS);
 			if (dc_pop(&datum) == DC_SUCCESS){
-				if (tmpint < 0)
+				if (tmpint < 0) {
 					fprintf(stderr,
 							"%s: array index must be a nonnegative integer\n",
 							progname);
-				else
+					checkferror_output(stderr);
+				} else
 					dc_array_set(peekc, tmpint, datum);
 			}
 		}
@@ -505,17 +515,19 @@ between 2 and %d (inclusive)\n",
 			tmpint = -1;
 			if (datum.dc_type == DC_NUMBER)
 				tmpint = dc_num2int(datum.v.number, DC_TOSS);
-			if (tmpint < 0)
+			if (tmpint < 0) {
 				fprintf(stderr,
 						"%s: array index must be a nonnegative integer\n",
 						progname);
-			else
+				checkferror_output(stderr);
+			} else
 				dc_push(dc_array_get(peekc, tmpint));
 		}
 		return DC_EATONE;
 
 	default:	/* What did that user mean? */
 		fprintf(stderr, "%s: ", progname);
+		checkferror_output(stderr);
 		dc_show_id(stdout, c, " unimplemented\n");
 		break;
 	}
@@ -544,6 +556,7 @@ dc_evalstr DC_DECLARG((string))
 		fprintf(stderr,
 				"%s: eval called with non-string argument\n",
 				progname);
+		checkferror_output(stderr);
 		return DC_OKAY;
 	}
 	interrupt_seen = 0;
@@ -640,6 +653,7 @@ dc_evalstr DC_DECLARG((string))
 				return DC_FAIL;
 			}
 			fprintf(stderr, "%s: unexpected EOS\n", progname);
+			checkferror_output(stderr);
 			return DC_OKAY;
 		}
 	}
@@ -665,6 +679,7 @@ dc_evalfile DC_DECLARG((fp))
 	stdin_lookahead = EOF;
 	for (c=getc(fp); c!=EOF; c=peekc){
 		peekc = getc(fp);
+		checkferror_input(stdin);
 		/*
 		 * The following if() is the only place where ``stdin_lookahead''
 		 * might be set to other than EOF:
@@ -716,6 +731,7 @@ dc_evalfile DC_DECLARG((fp))
 							return DC_SUCCESS;
 						fprintf(stderr, "%s: Q command argument exceeded \
 string execution depth\n", progname);
+						checkferror_output(stderr);
 					}
 				}else{
 					dc_garbage("at top of stack", -1);
@@ -728,8 +744,11 @@ string execution depth\n", progname);
 			fprintf(stderr,
 					"%s: Q command argument exceeded string execution depth\n",
 					progname);
-			if (stdin_lookahead != peekc  &&  fp == stdin)
+			checkferror_output(stderr);
+			if (stdin_lookahead != peekc  &&  fp == stdin) {
 				peekc = getc(fp);
+				checkferror_input(stdin);
+			}
 			break;
 
 		case DC_INT:
@@ -771,6 +790,7 @@ string execution depth\n", progname);
 			if (ferror(fp))
 				goto error_fail;
 			fprintf(stderr, "%s: unexpected EOF\n", progname);
+			checkferror_output(stderr);
 			return DC_FAIL;
 		}
 	}
diff -pruN 1.06.94-3/dc/misc.c 1.06.94-3ubuntu1/dc/misc.c
--- 1.06.94-3/dc/misc.c	2006-03-29 12:43:03.000000000 +0100
+++ 1.06.94-3ubuntu1/dc/misc.c	2007-12-05 13:11:11.000000000 +0000
@@ -91,6 +91,7 @@ dc_show_id DC_DECLARG((fp, id, suffix))
 		fprintf(fp, "'%c' (%#o)%s", (unsigned int) id, id, suffix);
 	else
 		fprintf(fp, "%#o%s", (unsigned int) id, suffix);
+	checkferror_output(fp);
 }
 
 
diff -pruN 1.06.94-3/dc/numeric.c 1.06.94-3ubuntu1/dc/numeric.c
--- 1.06.94-3/dc/numeric.c	2006-06-04 10:15:02.000000000 +0100
+++ 1.06.94-3ubuntu1/dc/numeric.c	2007-12-05 13:11:11.000000000 +0000
@@ -124,6 +124,7 @@ dc_div DC_DECLARG((a, b, kscale, result)
 	bc_init_num((bc_num *)result);
 	if (bc_divide(CastNum(a), CastNum(b), (bc_num *)result, kscale)){
 		fprintf(stderr, "%s: divide by zero\n", progname);
+		checkferror_output(stderr);
 		return DC_DOMAIN_ERROR;
 	}
 	return DC_SUCCESS;
@@ -146,6 +147,7 @@ dc_divrem DC_DECLARG((a, b, kscale, quot
 	if (bc_divmod(CastNum(a), CastNum(b),
 						(bc_num *)quotient, (bc_num *)remainder, kscale)){
 		fprintf(stderr, "%s: divide by zero\n", progname);
+		checkferror_output(stderr);
 		return DC_DOMAIN_ERROR;
 	}
 	return DC_SUCCESS;
@@ -164,6 +166,7 @@ dc_rem DC_DECLARG((a, b, kscale, result)
 	bc_init_num((bc_num *)result);
 	if (bc_modulo(CastNum(a), CastNum(b), (bc_num *)result, kscale)){
 		fprintf(stderr, "%s: remainder by zero\n", progname);
+		checkferror_output(stderr);
 		return DC_DOMAIN_ERROR;
 	}
 	return DC_SUCCESS;
@@ -180,8 +183,10 @@ dc_modexp DC_DECLARG((base, expo, mod, k
 	bc_init_num((bc_num *)result);
 	if (bc_raisemod(CastNum(base), CastNum(expo), CastNum(mod),
 					(bc_num *)result, kscale)){
-		if (bc_is_zero(CastNum(mod)))
+		if (bc_is_zero(CastNum(mod))) {
 			fprintf(stderr, "%s: remainder by zero\n", progname);
+			checkferror_output(stderr);
+		}
 		return DC_DOMAIN_ERROR;
 	}
 	return DC_SUCCESS;
@@ -216,6 +221,7 @@ dc_sqrt DC_DECLARG((value, kscale, resul
 	tmp = bc_copy_num(CastNum(value));
 	if (!bc_sqrt(&tmp, kscale)){
 		fprintf(stderr, "%s: square root of negative number\n", progname);
+		checkferror_output(stderr);
 		bc_free_num(&tmp);
 		return DC_DOMAIN_ERROR;
 	}
@@ -419,8 +425,10 @@ dc_out_num DC_DECLARG((value, obase, new
 {
 	out_char('\0'); /* clear the column counter */
 	bc_out_num(CastNum(value), obase, out_char, 0);
-	if (newline_p == DC_WITHNL)
+	if (newline_p == DC_WITHNL) {
 		putchar ('\n');
+		checkferror_output(stdout);
+	}
 	if (discard_p == DC_TOSS)
 		dc_free_num(&value);
 }
@@ -465,6 +473,7 @@ dc_dump_num DC_DECLARG((dcvalue, discard
 
 	for (cur=top_of_stack; cur; cur=next) {
 		putchar(cur->digit);
+		checkferror_output(stdout);
 		next = cur->link;
 		free(cur);
 	}
@@ -582,6 +591,7 @@ out_char (ch)
 			out_col = 1;
 		}
 		putchar(ch);
+		checkferror_output(stderr);
 	}
 }
 
@@ -621,6 +631,7 @@ rt_error (mesg, va_alist)
 	vfprintf (stderr, mesg, args);
 	va_end (args);
 	fprintf (stderr, "\n");
+	checkferror_output(stderr);
 }
 
 
@@ -654,6 +665,7 @@ rt_warn (mesg, va_alist)
 	vfprintf (stderr, mesg, args);
 	va_end (args);
 	fprintf (stderr, "\n");
+	checkferror_output(stderr);
 }
 
 
diff -pruN 1.06.94-3/dc/stack.c 1.06.94-3ubuntu1/dc/stack.c
--- 1.06.94-3/dc/stack.c	2006-03-29 12:42:31.000000000 +0100
+++ 1.06.94-3ubuntu1/dc/stack.c	2007-12-05 13:11:11.000000000 +0000
@@ -38,7 +38,10 @@
 #include "dc-regdef.h"
 
 /* an oft-used error message: */
-#define Empty_Stack	fprintf(stderr, "%s: stack empty\n", progname)
+#define Empty_Stack do{					\
+    fprintf(stderr, "%s: stack empty\n", progname);	\
+    checkferror_output(stderr);				\
+  }while(0)
 
 
 /* simple linked-list implementation suffices: */
@@ -94,6 +97,7 @@ dc_binop DC_DECLARG((op, kscale))
 	if (dc_stack->value.dc_type!=DC_NUMBER
 			|| dc_stack->link->value.dc_type!=DC_NUMBER){
 		fprintf(stderr, "%s: non-numeric value\n", progname);
+		checkferror_output(stderr);
 		return;
 	}
 	(void)dc_pop(&b);
@@ -134,6 +138,7 @@ dc_binop2 DC_DECLARG((op, kscale))
 	if (dc_stack->value.dc_type!=DC_NUMBER
 			|| dc_stack->link->value.dc_type!=DC_NUMBER){
 		fprintf(stderr, "%s: non-numeric value\n", progname);
+		checkferror_output(stderr);
 		return;
 	}
 	(void)dc_pop(&b);
@@ -172,6 +177,7 @@ dc_cmpop DC_DECLVOID()
 	if (dc_stack->value.dc_type!=DC_NUMBER
 			|| dc_stack->link->value.dc_type!=DC_NUMBER){
 		fprintf(stderr, "%s: non-numeric value\n", progname);
+		checkferror_output(stderr);
 		return 0;
 	}
 	(void)dc_pop(&b);
@@ -209,6 +215,7 @@ dc_triop DC_DECLARG((op, kscale))
 			|| dc_stack->link->value.dc_type!=DC_NUMBER
 			|| dc_stack->link->link->value.dc_type!=DC_NUMBER){
 		fprintf(stderr, "%s: non-numeric value\n", progname);
+		checkferror_output(stderr);
 		return;
 	}
 	(void)dc_pop(&c);
@@ -327,6 +334,7 @@ dc_register_get DC_DECLARG((regid, resul
 	r = dc_register[regid];
 	if (r==NULL || r->value.dc_type==DC_UNINITIALIZED){
 		fprintf(stderr, "%s: register ", progname);
+		checkferror_output(stderr);
 		dc_show_id(stderr, regid, " is empty\n");
 		return DC_FAIL;
 	}
@@ -401,6 +409,7 @@ dc_register_pop DC_DECLARG((stackid, res
 	r = dc_register[stackid];
 	if (r == NULL){
 		fprintf(stderr, "%s: stack register ", progname);
+		checkferror_output(stderr);
 		dc_show_id(stderr, stackid, " is empty\n");
 		return DC_FAIL;
 	}
diff -pruN 1.06.94-3/dc/string.c 1.06.94-3ubuntu1/dc/string.c
--- 1.06.94-3/dc/string.c	2006-03-29 14:08:25.000000000 +0100
+++ 1.06.94-3ubuntu1/dc/string.c	2007-12-05 13:11:11.000000000 +0000
@@ -101,6 +101,7 @@ dc_out_str DC_DECLARG((value, newline, d
 	fwrite(value->s_ptr, value->s_len, sizeof *value->s_ptr, stdout);
 	if (newline == DC_WITHNL)
 		putchar('\n');
+	checkferror_output(stdout);
 	if (discard_flag == DC_TOSS)
 		dc_free_str(&value);
 }
@@ -176,6 +177,7 @@ dc_readstring DC_DECLARG((fp, ldelim, rd
 		}
 		*p++ = c;
 	}
+	checkferror_input(fp);
 	return dc_makestring(line_buf, (size_t)(p-line_buf));
 }
 
diff -pruN 1.06.94-3/debian/control 1.06.94-3ubuntu1/debian/control
--- 1.06.94-3/debian/control	2007-12-05 13:12:25.000000000 +0000
+++ 1.06.94-3ubuntu1/debian/control	2007-12-05 13:11:11.000000000 +0000
@@ -1,7 +1,8 @@
 Source: bc
 Section: math
 Priority: standard
-Maintainer: John Hasler <[EMAIL PROTECTED]>
+Maintainer: Ubuntu Core Developers <[EMAIL PROTECTED]>
+XSBC-Original-Maintainer: John Hasler <[EMAIL PROTECTED]>
 Standards-Version: 3.7.2.2
 Build-Depends: bison, debhelper (>= 4), file, flex, libreadline5-dev | libreadline-dev, texi2html, texinfo
 
diff -pruN 1.06.94-3/h/number.h 1.06.94-3ubuntu1/h/number.h
--- 1.06.94-3/h/number.h	2006-06-09 18:04:31.000000000 +0100
+++ 1.06.94-3ubuntu1/h/number.h	2007-12-05 13:11:11.000000000 +0000
@@ -150,4 +150,7 @@ _PROTOTYPE(int bc_sqrt, (bc_num *num, in
 _PROTOTYPE(void bc_out_num, (bc_num num, int o_base, void (* out_char)(int),
 			     int leading_zero));
 
+_PROTOTYPE(void checkferror_input, (FILE*));
+_PROTOTYPE(void checkferror_output, (FILE*));
+
 #endif
diff -pruN 1.06.94-3/lib/number.c 1.06.94-3ubuntu1/lib/number.c
--- 1.06.94-3/lib/number.c	2006-06-09 18:04:31.000000000 +0100
+++ 1.06.94-3ubuntu1/lib/number.c	2007-12-05 13:11:11.000000000 +0000
@@ -1778,6 +1778,7 @@ static void
 out_char (int c)
 {
   putchar(c);
+  checkferror_output(stdout);
 }
 
 
@@ -1787,6 +1788,7 @@ pn (num)
 {
   bc_out_num (num, 10, out_char, 0);
   out_char ('\n');
+  checkferror_output(stdout);
 }
 
 
@@ -1801,6 +1803,28 @@ pv (name, num, len)
   printf ("%s=", name);
   for (i=0; i<len; i++) printf ("%c",BCD_CHAR(num[i]));
   printf ("\n");
+  checkferror_output(stdout);
 }
 
 #endif
+
+/* check ferror() status and if so die */
+void
+checkferror_input (fp)
+	FILE *fp;
+{
+	if (ferror(fp)) {
+		perror("dc: could not read input file");
+		exit(EXIT_FAILURE);
+	}
+}
+
+void
+checkferror_output (fp)
+	FILE *fp;
+{
+	if (ferror(fp)) {
+		perror("dc: could not write output file");
+		exit(EXIT_FAILURE);
+	}
+}
diff -pruN 1.06.94-3/lib/testmul.c 1.06.94-3ubuntu1/lib/testmul.c
--- 1.06.94-3/lib/testmul.c	2001-05-13 20:05:45.000000000 +0100
+++ 1.06.94-3ubuntu1/lib/testmul.c	2007-12-05 13:11:11.000000000 +0000
@@ -1,6 +1,8 @@
 /* compute the crossover for recursive and simple multiplication */
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include "number.h"
 #ifndef VARARGS
@@ -57,6 +59,7 @@ rt_error (mesg, va_alist)
   va_end (args);
   
   fprintf (stderr, "Runtime error: %s\n", error_mesg);
+  checkferror_output(stderr);
 }
 
 /* A runtime warning tells of some action taken by the processor that
@@ -90,12 +93,14 @@ rt_warn (mesg, va_alist)
   va_end (args);
 
   fprintf (stderr, "Runtime warning: %s\n", error_mesg);
+  checkferror_output(stderr);
 }
 
 void
 out_char (int ch)
 {
   putchar (ch);
+  checkferror_output(stdout);
 }
 
 /* Time stuff !!! */
@@ -147,21 +152,28 @@ int main (int argc, char **argv)
   bc_init_num (&big);
   bc_int2num (&ten, 10);
 
-  if (debug)
+  if (debug) {
     fprintf (stderr, "Timings are for %d multiplies\n"
 	             "Minimum time is %d seconds\n", test_n,
 	     test_time/CLOCKS_PER_SEC);
+    checkferror_output(stderr);
+  }
 
   /* Two of the same size */
   min = 10;
   max = 500;
 
-  if (debug)
+  if (debug) {
     fprintf (stderr, "Testing numbers of the same length.\n");
+    checkferror_output(stderr);
+  }
 
   while (min < max) {
     mid = (min+max)/2;
-    if (debug) fprintf (stderr,"Checking %d...\n", mid);
+    if (debug) {
+      fprintf (stderr,"Checking %d...\n", mid);
+      checkferror_output(stderr);
+    }
 
     bc_int2num (&expo, mid);
     bc_raise (ten, expo, &num, 0);
@@ -183,12 +195,16 @@ int main (int argc, char **argv)
     if (debug) {
       fprintf (stderr, "n1 = %d :: n2 = %d\n", n1, n2);
       fprintf (stderr, "p1 = %f :: p2 = %f\n", permul1, permul2);
+      checkferror_output(stderr);
     }
   }  
 
-  if (debug)
+  if (debug) {
     fprintf (stderr, "Base digits crossover at %d digits\n", min);
+    checkferror_output(stderr);
+  }
   printf ("#define MUL_BASE_DIGITS %d\n", 2*min);
+  checkferror_output(stdout);
 
 
 #if 0
@@ -204,12 +220,17 @@ int main (int argc, char **argv)
   min = min / 2;
   max = 500;
 
-  if (debug)
+  if (debug) {
     fprintf (stderr, "Testing numbers of the different length.\n");
+    checkferror_output(stderr);
+  }
 
   while (min < max) {
     mid = (min+max)/2;
-    if (debug) fprintf (stderr, "Checking %d...\n", mid);
+    if (debug) {
+      fprintf (stderr, "Checking %d...\n", mid);
+      checkferror_output(stderr);
+    }
 
     bc_int2num (&expo, mid-smallsize);
     bc_raise (ten, expo, &num, 0);
@@ -231,12 +252,16 @@ int main (int argc, char **argv)
     if (debug) {
       fprintf (stderr, "n1 = %d :: n2 = %d\n", n1, n2);
       fprintf (stderr, "p1 = %f :: p2 = %f\n", permul1, permul2);
+      checkferror_output(stderr);
     }
   }  
   
-  if (debug)
+  if (debug) {
     fprintf (stderr, "Non equal digits crossover at %d total digits\n", min);
+    checkferror_output(stderr);
+  }
   printf ("#define MUL_SMALL_DIGITS = %d\n", min);
+  checkferror_output(stdout);
 
 #endif
 

Reply via email to