From fe0493c0bc7be6afd6a9d9cfdc8235dc2e0704d5 Mon Sep 17 00:00:00 2001 From: Rick Bird Date: Fri, 25 Mar 2011 14:13:27 -0400 Subject: [PATCH] PennMUSH Incorporation. 182p2 - math function crashes fix --- src/funmath.c | 62 ++++++++++++++++++++++++++++++++++++++------------- src/funstr.c | 6 +++-- src/utils.c | 9 +------- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/funmath.c b/src/funmath.c index a37167e..009f135 100644 --- a/src/funmath.c +++ b/src/funmath.c @@ -459,8 +459,10 @@ FUNCTION(fun_vmax) NVAL a, b; /* return if a list is empty */ - if (!args[0] || !args[1]) + if (!args[0] || !args[1]) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } if (!delim_check(buff, bp, nargs, args, 3, &sep)) return; @@ -468,8 +470,10 @@ FUNCTION(fun_vmax) p2 = trim_space_sep(args[1], sep); /* return if a list is empty */ - if (!*p1 || !*p2) + if (!*p1 || !*p2) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } /* max the vectors */ start = *bp; @@ -501,8 +505,10 @@ FUNCTION(fun_vmin) NVAL a, b; /* return if a list is empty */ - if (!args[0] || !args[1]) + if (!args[0] || !args[1]) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } if (!delim_check(buff, bp, nargs, args, 3, &sep)) return; @@ -543,8 +549,10 @@ FUNCTION(fun_vadd) char sep; /* return if a list is empty */ - if (!args[0] || !args[1]) + if (!args[0] || !args[1]) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } if (!delim_check(buff, bp, nargs, args, 3, &sep)) return; @@ -552,8 +560,10 @@ FUNCTION(fun_vadd) p2 = trim_space_sep(args[1], sep); /* return if a list is empty */ - if (!*p1 || !*p2) + if (!*p1 || !*p2) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } /* add the vectors */ start = *bp; @@ -582,8 +592,10 @@ FUNCTION(fun_vsub) char sep; /* return if a list is empty */ - if (!args[0] || !args[1]) + if (!args[0] || !args[1]) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } if (!delim_check(buff, bp, nargs, args, 3, &sep)) return; @@ -591,8 +603,10 @@ FUNCTION(fun_vsub) p2 = trim_space_sep(args[1], sep); /* return if a list is empty */ - if (!*p1 || !*p2) + if (!*p1 || !*p2) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } /* subtract the vectors */ start = *bp; @@ -621,8 +635,10 @@ FUNCTION(fun_vmul) char sep; /* return if a list is empty */ - if (!args[0] || !args[1]) + if (!args[0] || !args[1]) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } if (!delim_check(buff, bp, nargs, args, 3, &sep)) return; @@ -630,8 +646,10 @@ FUNCTION(fun_vmul) p2 = trim_space_sep(args[1], sep); /* return if a list is empty */ - if (!*p1 || !*p2) + if (!*p1 || !*p2) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } /* multiply the vectors */ start = *bp; @@ -678,8 +696,10 @@ FUNCTION(fun_vdot) char sep; /* return if a list is empty */ - if (!args[0] || !args[1]) + if (!args[0] || !args[1]) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } if (!delim_check(buff, bp, nargs, args, 3, &sep)) return; @@ -687,8 +707,10 @@ FUNCTION(fun_vdot) p2 = trim_space_sep(args[1], sep); /* return if a list is empty */ - if (!*p1 || !*p2) + if (!*p1 || !*p2) { + safe_str(T("#-1 VECTORS MUST BE SAME DIMENSIONS"), buff, bp); return; + } /* multiply the vectors */ product = 0; @@ -711,16 +733,20 @@ FUNCTION(fun_vmag) char sep; /* return if a list is empty */ - if (!args[0]) + if (!args[0]) { + safe_str(T("#-1 VECTOR MUST NOT BE EMPTY"), buff, bp); return; + } if (!delim_check(buff, bp, nargs, args, 2, &sep)) return; p1 = trim_space_sep(args[0], sep); /* return if a list is empty */ - if (!*p1) + if (!*p1) { + safe_str(T("#-1 VECTOR MUST NOT BE EMPTY"), buff, bp); return; + } /* sum the squares */ num = parse_number(split_token(&p1, sep)); @@ -742,16 +768,20 @@ FUNCTION(fun_vunit) char sep; /* return if a list is empty */ - if (!args[0]) + if (!args[0]) { + safe_str(T("#-1 VECTOR MUST NOT BE EMPTY"), buff, bp); return; + } if (!delim_check(buff, bp, nargs, args, 2, &sep)) return; p1 = trim_space_sep(args[0], sep); /* return if a list is empty */ - if (!*p1) + if (!*p1) { + safe_str(T("#-1 VECTOR MUST NOT BE EMPTY"), buff, bp); return; + } /* copy the vector, since we have to walk it twice... */ strcpy(tbuf, p1); @@ -1679,7 +1709,7 @@ FUNCTION(fun_lmath) MATH *op; /* Allocate memory */ - ptr = (char **) mush_malloc(BUFFER_LEN, "string"); + ptr = (char **) mush_malloc(sizeof(char *) * BUFFER_LEN, "string"); if (!delim_check(buff, bp, nargs, args, 3, &sep)) { mush_free((Malloc_t) ptr, "string"); diff --git a/src/funstr.c b/src/funstr.c index 5fe9cfe..52b05b0 100644 --- a/src/funstr.c +++ b/src/funstr.c @@ -1363,16 +1363,18 @@ init_tag_hashtab(void) FUNCTION(fun_ord) { char *m; + unsigned char what; size_t len = 0; if (!args[0] || !args[0][0]) { safe_str(T("#-1 FUNCTION EXPECTS ONE CHARACTER"), buff, bp); return; } m = remove_markup(args[0], &len); + what = (unsigned char) *m; if (len != 2) /* len includes trailing nul */ - safe_str(T("#-1 FUNCTION EXPECTS ONE CHARACTER"), buff, bp); - else if (isprint((unsigned char) *m)) + safe_str(T("#-1 FUNCTION (ORD) EXPECTS ONE CHARACTER"), buff, bp); + else if(isprint(what) || what == '\n') safe_integer((unsigned char) *m, buff, bp); else safe_str(T("#-1 UNPRINTABLE CHARACTER"), buff, bp); diff --git a/src/utils.c b/src/utils.c index 462e903..ac8a068 100644 --- a/src/utils.c +++ b/src/utils.c @@ -49,7 +49,6 @@ dbref find_entrance(dbref door); void initialize_mt(void); static unsigned long genrand_int32(void); -static long genrand_int31(void); static void init_genrand(unsigned long); static void init_by_array(unsigned long *, int); extern int local_can_interact_first(dbref from, dbref to, int type); @@ -628,12 +627,6 @@ genrand_int32(void) return y; } -/* generates a random number on [0,0x7fffffff]-interval */ -static long -genrand_int31(void) -{ - return (long) (genrand_int32() >> 1); -} /** Get a uniform random long between low and high values, inclusive. * Based on MUX's RandomINT32() @@ -679,7 +672,7 @@ get_random_long(long low, long high) n_limit = ULONG_MAX - (ULONG_MAX % x); do { - n = genrand_int31(); + n = genrand_int32(); } while (n >= n_limit); return low + (n % x); -- 2.30.2