| 359 | | char* |
| 360 | | i_realloc(loc, len) |
| 361 | | char *loc; |
| 362 | | unsigned len; |
| 363 | | { |
| 364 | | struct glob *ob; |
| 365 | | struct glob *preob; |
| 366 | | int rs; |
| 367 | | char *ptr = loc; |
| 368 | | struct glob **he; |
| 369 | | int i; |
| 370 | | |
| 371 | | |
| 372 | | |
| 373 | | if (firsttime) { |
| 374 | | char *s = "i_realloc: called before i_malloc?\n"; |
| 375 | | SWRITE(debfd, s);
|
| 376 | | i_choke(); |
| 377 | | return (char*)0; |
| 378 | | } |
| 379 | | |
| 380 | | |
| 381 | | |
| 382 | | #if LET0BE1 > 0
|
| 383 | | if (!len) |
| 384 | | len = 1; |
| 385 | | #endif |
| 386 | | if (len < 1 || len > lengthlimit) { |
| 387 | | (void)sprintf(msbuf, "i_realloc: bogus len=%d\n", len); |
| 388 | | (void)SWRITE(debfd, msbuf);
|
| 389 | | i_choke(); |
| 390 | | return (char*)0; |
| 391 | | } |
| 392 | | |
| 393 | | |
| 394 | | |
| 395 | | he = &hashtbl[HASH(loc)];
|
| 396 | | for (preob = 0, ob = *he; ob && ob->base != loc; preob = ob, ob = ob->next); |
| 397 | | if (!ob) { |
| 398 | | (void)sprintf(msbuf, "i_realloc: bogus loc=0x%lx\n", |
| 399 | | (long) loc); |
| 400 | | (void)SWRITE(debfd, msbuf);
|
| 401 | | i_choke(); |
| 402 | | return (char*)0; |
| 403 | | } |
| 404 | | rs = ob->rst; |
| 405 | | |
| 406 | | |
| 407 | | |
| 408 | | for (i = ob->lop, ptr -= i; i > 0; i--) |
| 409 | | if ((0xff & (int)(*ptr++)) != (0xff & NEXTRN(rs))) {
|
| 410 | | (void)sprintf(msbuf, "i_realloc: scribbled in 0x%lx[%d]\n", |
| 411 | | (long) loc, -i); |
| 412 | | (void)SWRITE(debfd, msbuf);
|
| 413 | | i_choke(); |
| 414 | | } |
| 415 | | for (i = ob->hip, ptr += ob->len; i > 0; i--) |
| 416 | | if ((0xff & (int)(*ptr++)) != (0xff & NEXTRN(rs))) {
|
| 417 | | (void)sprintf(msbuf, |
| 418 | | "i_realloc: scribbled in 0x%lx[%d+%d]\n", |
| 419 | | (long) loc, ob->len, ob->hip - i); |
| 420 | | (void)SWRITE(debfd, msbuf);
|
| 421 | | i_choke(); |
| 422 | | } |
| 423 | | |
| 424 | | |
| 425 | | |
| 426 | | if (preob) |
| 427 | | preob->next = ob->next; |
| 428 | | else |
| 429 | | *he = ob->next; |
| 430 | | |
| 431 | | |
| 432 | | |
| 433 | | if (!(ptr = (char*)realloc(loc - ob->lop, len + lopad + hipad))) { |
| 434 | | (void)sprintf(msbuf, "i_realloc: malloc failed len=%d\n", len); |
| 435 | | (void)SWRITE(debfd, msbuf);
|
| 436 | | i_choke(); |
| 437 | | return (char*)0; |
| 438 | | } |
| 439 | | |
| 440 | | |
| 441 | | |
| 442 | | totlnbyts += len - ob->len; |
| 443 | | ob->flg = OBREALLOC;
|
| 444 | | ob->id = ++globid; |
| 445 | | ob->len = len; |
| 446 | | ob->lop = lopad; |
| 447 | | ob->hip = hipad; |
| 448 | | ob->rst = rnstate; |
| 449 | | for (i = lopad; i-- > 0; *ptr++ = NEXTRN(rnstate));
|
| 450 | | ob->base = ptr; |
| 451 | | he = &hashtbl[HASH(ptr)];
|
| 452 | | for (i = hipad, ptr += len; i-- > 0; *ptr++ = NEXTRN(rnstate));
|
| 453 | | ob->next = *he; |
| 454 | | *he = ob; |
| 455 | | return ob->base; |
| 456 | | } |