bcode.c (256281) | bcode.c (265533) |
---|---|
1/* $OpenBSD: bcode.c,v 1.40 2009/10/27 23:59:37 deraadt Exp $ */ | 1/* $OpenBSD: bcode.c,v 1.45 2012/11/07 11:06:14 otto Exp $ */ |
2 3/* 4 * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19#include <sys/cdefs.h> | 2 3/* 4 * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19#include <sys/cdefs.h> |
20__FBSDID("$FreeBSD: stable/10/usr.bin/dc/bcode.c 244861 2012-12-30 15:20:27Z kevlo $"); | 20__FBSDID("$FreeBSD: stable/10/usr.bin/dc/bcode.c 265533 2014-05-07 08:06:54Z delphij $"); |
21 22#include <err.h> 23#include <limits.h> 24#include <openssl/ssl.h> 25#include <signal.h> 26#include <stdio.h> 27#include <stdlib.h> 28#include <string.h> 29 30#include "extern.h" 31 | 21 22#include <err.h> 23#include <limits.h> 24#include <openssl/ssl.h> 25#include <signal.h> 26#include <stdio.h> 27#include <stdlib.h> 28#include <string.h> 29 30#include "extern.h" 31 |
32#define __inline | 32/* #define DEBUGGING */ |
33 34#define MAX_ARRAY_INDEX 2048 35#define READSTACK_SIZE 8 36 37#define NO_ELSE -2 /* -1 is EOF */ 38#define REG_ARRAY_SIZE_SMALL (UCHAR_MAX + 1) 39#define REG_ARRAY_SIZE_BIG (UCHAR_MAX + 1 + USHRT_MAX + 1) 40 --- 207 unchanged lines hidden (view full) --- 248 if (bmachine.readstack == NULL) 249 err(1, NULL); 250 bmachine.obase = bmachine.ibase = 10; 251} 252 253u_int 254bmachine_scale(void) 255{ | 33 34#define MAX_ARRAY_INDEX 2048 35#define READSTACK_SIZE 8 36 37#define NO_ELSE -2 /* -1 is EOF */ 38#define REG_ARRAY_SIZE_SMALL (UCHAR_MAX + 1) 39#define REG_ARRAY_SIZE_BIG (UCHAR_MAX + 1 + USHRT_MAX + 1) 40 --- 207 unchanged lines hidden (view full) --- 248 if (bmachine.readstack == NULL) 249 err(1, NULL); 250 bmachine.obase = bmachine.ibase = 10; 251} 252 253u_int 254bmachine_scale(void) 255{ |
256 return (bmachine.scale); | 256 return bmachine.scale; |
257} 258 259/* Reset the things needed before processing a (new) file */ 260void 261reset_bmachine(struct source *src) 262{ 263 264 bmachine.readsp = 0; --- 158 unchanged lines hidden (view full) --- 423 424 normalize(n, 0); 425 return (BN_get_word(n->number)); 426} 427 428void 429negate(struct number *n) 430{ | 257} 258 259/* Reset the things needed before processing a (new) file */ 260void 261reset_bmachine(struct source *src) 262{ 263 264 bmachine.readsp = 0; --- 158 unchanged lines hidden (view full) --- 423 424 normalize(n, 0); 425 return (BN_get_word(n->number)); 426} 427 428void 429negate(struct number *n) 430{ |
431 | |
432 BN_set_negative(n->number, !BN_is_negative(n->number)); 433} 434 435static __inline void 436push_number(struct number *n) 437{ 438 439 stack_pushnumber(&bmachine.stack, n); --- 250 unchanged lines hidden (view full) --- 690 691static u_int 692count_digits(const struct number *n) 693{ 694 struct number *int_part, *fract_part; 695 u_int i; 696 697 if (BN_is_zero(n->number)) | 431 BN_set_negative(n->number, !BN_is_negative(n->number)); 432} 433 434static __inline void 435push_number(struct number *n) 436{ 437 438 stack_pushnumber(&bmachine.stack, n); --- 250 unchanged lines hidden (view full) --- 689 690static u_int 691count_digits(const struct number *n) 692{ 693 struct number *int_part, *fract_part; 694 u_int i; 695 696 if (BN_is_zero(n->number)) |
698 return (n->scale ? n->scale : 1); | 697 return n->scale ? n->scale : 1; |
699 700 int_part = new_number(); 701 fract_part = new_number(); 702 fract_part->scale = n->scale; 703 split_number(n, int_part->number, fract_part->number); 704 705 i = 0; 706 while (!BN_is_zero(int_part->number)) { --- 459 unchanged lines hidden (view full) --- 1166 push_number(rmod); 1167 free_number(a); 1168 free_number(b); 1169} 1170 1171static void 1172bexp(void) 1173{ | 698 699 int_part = new_number(); 700 fract_part = new_number(); 701 fract_part->scale = n->scale; 702 split_number(n, int_part->number, fract_part->number); 703 704 i = 0; 705 while (!BN_is_zero(int_part->number)) { --- 459 unchanged lines hidden (view full) --- 1165 push_number(rmod); 1166 free_number(a); 1167 free_number(b); 1168} 1169 1170static void 1171bexp(void) 1172{ |
1174 struct number *a, *p, *r; 1175 u_int rscale; 1176 bool neg; | 1173 struct number *a, *p; 1174 struct number *r; 1175 bool neg; 1176 u_int rscale; |
1177 1178 p = pop_number(); 1179 if (p == NULL) { 1180 return; 1181 } 1182 a = pop_number(); 1183 if (a == NULL) { 1184 push_number(p); 1185 return; 1186 } 1187 1188 if (p->scale != 0) { 1189 BIGNUM *i, *f; 1190 i = BN_new(); 1191 bn_checkp(i); 1192 f = BN_new(); 1193 bn_checkp(f); 1194 split_number(p, i, f); 1195 if (!BN_is_zero(f)) | 1177 1178 p = pop_number(); 1179 if (p == NULL) { 1180 return; 1181 } 1182 a = pop_number(); 1183 if (a == NULL) { 1184 push_number(p); 1185 return; 1186 } 1187 1188 if (p->scale != 0) { 1189 BIGNUM *i, *f; 1190 i = BN_new(); 1191 bn_checkp(i); 1192 f = BN_new(); 1193 bn_checkp(f); 1194 split_number(p, i, f); 1195 if (!BN_is_zero(f)) |
1196 warnx("Runtime warning: non-zero fractional part " 1197 "in exponent"); | 1196 warnx("Runtime warning: non-zero fractional part in exponent"); |
1198 BN_free(i); 1199 BN_free(f); 1200 } 1201 1202 normalize(p, 0); 1203 1204 neg = false; 1205 if (BN_is_negative(p->number)) { --- 572 unchanged lines hidden --- | 1197 BN_free(i); 1198 BN_free(f); 1199 } 1200 1201 normalize(p, 0); 1202 1203 neg = false; 1204 if (BN_is_negative(p->number)) { --- 572 unchanged lines hidden --- |