Fri Sep 1 00:39:41 PDT 2000 Michael Jennings <mej@eterm.org>

That should fix the crashes.  Somehow I managed to temporarily forget
	about pointer arithmetic.  And somehow I thought trying to dereference
	a pixmap ID would be a good thing.  Sigh.  I need sleep.


SVN revision: 3292
This commit is contained in:
Michael Jennings 2000-09-01 07:23:08 +00:00
parent cdbb53b4bf
commit f1bf2bfb54
4 changed files with 41 additions and 25 deletions

View File

@ -3852,3 +3852,10 @@ Thu Aug 31 23:02:10 PDT 2000 Michael Jennings <mej@eterm.org>
libmej using the existing allocation tracking routines. libmej using the existing allocation tracking routines.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Fri Sep 1 00:39:41 PDT 2000 Michael Jennings <mej@eterm.org>
That should fix the crashes. Somehow I managed to temporarily forget
about pointer arithmetic. And somehow I thought trying to dereference
a pixmap ID would be a good thing. Sigh. I need sleep.
-------------------------------------------------------------------------------

View File

@ -33,7 +33,8 @@ static const char cvs_ident[] = "$Id$";
static void memrec_add_var(memrec_t *, void *, size_t); static void memrec_add_var(memrec_t *, void *, size_t);
static void memrec_rem_var(memrec_t *, const char *, const char *, unsigned long, void *); static void memrec_rem_var(memrec_t *, const char *, const char *, unsigned long, void *);
static void memrec_chg_var(memrec_t *, const char *, const char *, unsigned long, void *, void *, size_t); static void memrec_chg_var(memrec_t *, const char *, const char *, unsigned long, void *, void *, size_t);
static void memrec_dump(memrec_t *); static void memrec_dump_pointers(memrec_t *);
static void memrec_dump_resources(memrec_t *);
/* /*
* These're added for a pretty obvious reason -- they're implemented towards * These're added for a pretty obvious reason -- they're implemented towards
@ -68,8 +69,8 @@ memrec_add_var(memrec_t *memrec, void *ptr, size_t size)
if ((memrec->ptrs = (ptr_t *) realloc(memrec->ptrs, sizeof(ptr_t) * memrec->cnt)) == NULL) { if ((memrec->ptrs = (ptr_t *) realloc(memrec->ptrs, sizeof(ptr_t) * memrec->cnt)) == NULL) {
D_MEM(("Unable to reallocate pointer list -- %s\n", strerror(errno))); D_MEM(("Unable to reallocate pointer list -- %s\n", strerror(errno)));
} }
D_MEM(("Adding variable of size %lu at %8p\n", size, ptr));
p = memrec->ptrs + memrec->cnt - 1; p = memrec->ptrs + memrec->cnt - 1;
D_MEM(("Adding variable of size %lu at %8p. Storing as pointer #%lu at %8p (from %8p).\n", size, ptr, memrec->cnt, p, memrec->ptrs));
p->ptr = ptr; p->ptr = ptr;
p->size = size; p->size = size;
} }
@ -92,7 +93,7 @@ memrec_rem_var(memrec_t *memrec, const char *var, const char *filename, unsigned
return; return;
} }
memrec->cnt--; memrec->cnt--;
D_MEM(("Removing variable of size %lu at %8p\n", p->size, p->ptr)); D_MEM(("Removing variable %s (%8p) of size %lu which is stored at %8p (from %8p)\n", var, ptr, p->size, p, memrec->ptrs));
memmove(p, p + 1, sizeof(ptr_t) * (memrec->cnt - i)); memmove(p, p + 1, sizeof(ptr_t) * (memrec->cnt - i));
memrec->ptrs = (ptr_t *) realloc(memrec->ptrs, sizeof(ptr_t) * memrec->cnt); memrec->ptrs = (ptr_t *) realloc(memrec->ptrs, sizeof(ptr_t) * memrec->cnt);
} }
@ -114,13 +115,13 @@ memrec_chg_var(memrec_t *memrec, const char *var, const char *filename, unsigned
D_MEM(("ERROR: File %s, line %d attempted to realloc variable %s (%8p) which was not allocated with MALLOC/REALLOC\n", filename, line, var, oldp)); D_MEM(("ERROR: File %s, line %d attempted to realloc variable %s (%8p) which was not allocated with MALLOC/REALLOC\n", filename, line, var, oldp));
return; return;
} }
D_MEM(("Changing variable of %lu bytes at %8p to one of %lu bytes at %8p\n", p->size, p->ptr, size, newp)); D_MEM(("Changing variable %s (%8p, %lu -> %8p, %lu) stored at %8p (from %8p)\n", var, oldp, p->size, newp, size, p, memrec->ptrs));
p->ptr = newp; p->ptr = newp;
p->size = size; p->size = size;
} }
static void static void
memrec_dump(memrec_t *memrec) memrec_dump_pointers(memrec_t *memrec)
{ {
register ptr_t *p; register ptr_t *p;
unsigned long i, j, k, l, total = 0; unsigned long i, j, k, l, total = 0;
@ -136,12 +137,13 @@ memrec_dump(memrec_t *memrec)
memset(buff, 0, sizeof(buff)); memset(buff, 0, sizeof(buff));
/* First, dump the contents of the memrec->ptrs[] array. */ /* First, dump the contents of the memrec->ptrs[] array. */
for (p = memrec->ptrs, j = 0; j < len; p++, j += 8) { for (p = memrec->ptrs, j = 0; j < len; j += 8) {
fprintf(LIBMEJ_DEBUG_FD, "DUMP :: %07lu | %8p | %06lu | %07x | ", (unsigned long) 0, memrec->ptrs, (unsigned long) (sizeof(ptr_t) * memrec->cnt), (unsigned int) j); fprintf(LIBMEJ_DEBUG_FD, "DUMP :: %07lu | %8p | %06lu | %07x | ", (unsigned long) 0, memrec->ptrs, (unsigned long) (sizeof(ptr_t) * memrec->cnt), (unsigned int) j);
/* l is the number of characters we're going to output */ /* l is the number of characters we're going to output */
l = ((len - j < 8) ? (len - j) : (8)); l = ((len - j < 8) ? (len - j) : (8));
/* Copy l bytes (up to 8) from memrec->ptrs[] (p) to buffer */ /* Copy l bytes (up to 8) from memrec->ptrs[] (p) to buffer */
memcpy(buff, p + j, l); memset(buff, 0, sizeof(buff));
memcpy(buff, ((char *) p) + j, l);
for (k = 0; k < l; k++) { for (k = 0; k < l; k++) {
fprintf(LIBMEJ_DEBUG_FD, "%02x ", buff[k]); fprintf(LIBMEJ_DEBUG_FD, "%02x ", buff[k]);
} }
@ -156,7 +158,7 @@ memrec_dump(memrec_t *memrec)
} }
/* Now print out each pointer and its contents. */ /* Now print out each pointer and its contents. */
for (p = memrec->ptrs, i = 0; i < memrec->cnt; p++, i++) { for (i = 0; i < memrec->cnt; p++, i++) {
/* Add this pointer's size to our total */ /* Add this pointer's size to our total */
total += p->size; total += p->size;
for (j = 0; j < p->size; j += 8) { for (j = 0; j < p->size; j += 8) {
@ -164,7 +166,9 @@ memrec_dump(memrec_t *memrec)
/* l is the number of characters we're going to output */ /* l is the number of characters we're going to output */
l = ((p->size - j < 8) ? (p->size - j) : (8)); l = ((p->size - j < 8) ? (p->size - j) : (8));
/* Copy l bytes (up to 8) from p->ptr to buffer */ /* Copy l bytes (up to 8) from p->ptr to buffer */
memcpy(buff, p->ptr + j, l); memset(buff, 0, sizeof(buff));
memcpy(buff, ((char *) p->ptr) + j, l);
buff[l] = 0;
for (k = 0; k < l; k++) { for (k = 0; k < l; k++) {
fprintf(LIBMEJ_DEBUG_FD, "%02x ", buff[k]); fprintf(LIBMEJ_DEBUG_FD, "%02x ", buff[k]);
} }
@ -182,6 +186,18 @@ memrec_dump(memrec_t *memrec)
fflush(LIBMEJ_DEBUG_FD); fflush(LIBMEJ_DEBUG_FD);
} }
static void
memrec_dump_resources(memrec_t *memrec)
{
register ptr_t *p;
unsigned long i, j, k, l, total = 0;
unsigned long len;
unsigned char buff[9];
ASSERT(memrec != NULL);
}
/******************** MEMORY ALLOCATION INTERFACE ********************/ /******************** MEMORY ALLOCATION INTERFACE ********************/
void * void *
libmej_malloc(const char *filename, unsigned long line, size_t size) libmej_malloc(const char *filename, unsigned long line, size_t size)
@ -289,7 +305,7 @@ libmej_strdup(const char *var, const char *filename, unsigned long line, const c
void void
libmej_dump_mem_tables(void) libmej_dump_mem_tables(void)
{ {
memrec_dump(&malloc_rec); memrec_dump_pointers(&malloc_rec);
} }
@ -328,7 +344,7 @@ libmej_x_free_pixmap(const char *var, const char *filename, unsigned long line,
void void
libmej_dump_pixmap_tables(void) libmej_dump_pixmap_tables(void)
{ {
memrec_dump(&pixmap_rec); memrec_dump_resources(&pixmap_rec);
} }
@ -367,5 +383,5 @@ libmej_x_free_gc(const char *var, const char *filename, unsigned long line, Disp
void void
libmej_dump_gc_tables(void) libmej_dump_gc_tables(void)
{ {
memrec_dump(&gc_rec); memrec_dump_resources(&gc_rec);
} }

View File

@ -252,6 +252,7 @@ safe_print_string(char *str, unsigned long len)
if (n + 2 >= rb_size) { if (n + 2 >= rb_size) {
rb_size *= 2; rb_size *= 2;
ret_buff = (char *) REALLOC(ret_buff, rb_size + 1); ret_buff = (char *) REALLOC(ret_buff, rb_size + 1);
p = ret_buff + n;
} }
if (*str < ' ') { if (*str < ' ') {
*p++ = '^'; *p++ = '^';

View File

@ -1579,7 +1579,7 @@ shell_expand(char *s)
register char *pbuff = s, *tmp1; register char *pbuff = s, *tmp1;
register unsigned long j, k, l = 0; register unsigned long j, k, l = 0;
char new[CONFIG_BUFF]; char new[CONFIG_BUFF];
unsigned char eval_escape = 1, eval_var = 1, eval_exec = 1, eval_func = 1, in_single = 0, in_double = 0; unsigned char in_single = 0, in_double = 0;
unsigned long cnt1 = 0, cnt2 = 0; unsigned long cnt1 = 0, cnt2 = 0;
const unsigned long max = CONFIG_BUFF - 1; const unsigned long max = CONFIG_BUFF - 1;
char *Command, *Output, *EnvVar; char *Command, *Output, *EnvVar;
@ -1594,7 +1594,7 @@ shell_expand(char *s)
switch (*pbuff) { switch (*pbuff) {
case '~': case '~':
D_OPTIONS(("Tilde detected.\n")); D_OPTIONS(("Tilde detected.\n"));
if (eval_var) { if (!in_single && !in_double) {
strncpy(new + j, getenv("HOME"), max - j); strncpy(new + j, getenv("HOME"), max - j);
cnt1 = strlen(getenv("HOME")) - 1; cnt1 = strlen(getenv("HOME")) - 1;
cnt2 = max - j - 1; cnt2 = max - j - 1;
@ -1605,7 +1605,7 @@ shell_expand(char *s)
break; break;
case '\\': case '\\':
D_OPTIONS(("Escape sequence detected.\n")); D_OPTIONS(("Escape sequence detected.\n"));
if (eval_escape || (in_single && *(pbuff + 1) == '\'')) { if (!in_single || (in_single && *(pbuff + 1) == '\'')) {
switch (tolower(*(++pbuff))) { switch (tolower(*(++pbuff))) {
case 'n': case 'n':
new[j] = '\n'; new[j] = '\n';
@ -1699,7 +1699,7 @@ shell_expand(char *s)
case '`': case '`':
#ifdef ALLOW_BACKQUOTE_EXEC #ifdef ALLOW_BACKQUOTE_EXEC
D_OPTIONS(("Backquotes detected. Evaluating expression.\n")); D_OPTIONS(("Backquotes detected. Evaluating expression.\n"));
if (eval_exec) { if (!in_single) {
Command = (char *) MALLOC(CONFIG_BUFF); Command = (char *) MALLOC(CONFIG_BUFF);
l = 0; l = 0;
for (pbuff++; *pbuff && *pbuff != '`' && l < max; pbuff++, l++) { for (pbuff++; *pbuff && *pbuff != '`' && l < max; pbuff++, l++) {
@ -1733,7 +1733,7 @@ shell_expand(char *s)
break; break;
case '$': case '$':
D_OPTIONS(("Environment variable detected. Evaluating.\n")); D_OPTIONS(("Environment variable detected. Evaluating.\n"));
if (eval_var) { if (!in_single) {
EnvVar = (char *) MALLOC(128); EnvVar = (char *) MALLOC(128);
switch (*(++pbuff)) { switch (*(++pbuff)) {
case '{': case '{':
@ -1776,16 +1776,8 @@ shell_expand(char *s)
case '\'': case '\'':
D_OPTIONS(("Single quotes detected.\n")); D_OPTIONS(("Single quotes detected.\n"));
if (in_single) { if (in_single) {
eval_var = 1;
eval_exec = 1;
eval_func = 1;
eval_escape = 1;
in_single = 0; in_single = 0;
} else { } else {
eval_var = 0;
eval_exec = 0;
eval_func = 0;
eval_escape = 0;
in_single = 1; in_single = 1;
} }
new[j] = *pbuff; new[j] = *pbuff;