summaryrefslogtreecommitdiff
path: root/print_raw.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2000-12-15 16:27:51 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2000-12-15 16:27:51 +0000
commitae84a54357ab7e180ba80b4cb90885f052ca335d (patch)
treeea4b6550d4ec4da54d34ca33999da1f8510802ca /print_raw.c
parent2a346ee6e6b733b2ec3e0945ee34a4a6bd49a4ab (diff)
downloadmpfr-ae84a54357ab7e180ba80b4cb90885f052ca335d.tar.gz
added error message when memory allocation fails
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@878 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'print_raw.c')
-rw-r--r--print_raw.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/print_raw.c b/print_raw.c
index b4e5385ca..e37ba56fa 100644
--- a/print_raw.c
+++ b/print_raw.c
@@ -71,7 +71,8 @@ mpfr_print_raw(x)
mpfr_srcptr x;
#endif
{
- char *str;
+ char *str;
+ unsigned long alloc_size;
if (MPFR_IS_NAN(x)) printf("NaN");
else if (MPFR_IS_INF(x)) {
@@ -86,11 +87,16 @@ mpfr_print_raw(x)
+ 11 for exponent (including sign)
= 17 + MPFR_ABSSIZE(x) * BITS_PER_MP_LIMB
*/
- str = (char *) (*_mp_allocate_func) ((17 + MPFR_ABSSIZE(x) * BITS_PER_MP_LIMB)*sizeof(char));
+ alloc_size = 17 + MPFR_ABSSIZE(x) * BITS_PER_MP_LIMB;
+ str = (char *) (*_mp_allocate_func) (alloc_size * sizeof(char));
+ if (str == NULL) {
+ fprintf (stderr, "Error in mpfr_print_raw: no more memory available\n");
+ exit (1);
+ }
mpfr_get_str_raw(str, x);
printf("%s", str);
- (*_mp_free_func) (str, (17 + MPFR_ABSSIZE(x) * BITS_PER_MP_LIMB)*sizeof(char));
+ (*_mp_free_func) (str, alloc_size * sizeof(char));
}
}