Changeset 32


Ignore:
Timestamp:
Feb 6, 2001, 7:21:38 PM (25 years ago)
Author:
umoeller
Message:

misc. changes

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/xstring.h

    r23 r32  
    153153    typedef XSTRFINDREPLACEC *PXSTRFINDREPLACEC;
    154154
     155    // V0.9.9 (2001-01-29) [lafaix]: constants added
     156    #define CRLF2LF TRUE
     157    #define LF2CRLF FALSE
     158
    155159    VOID XWPENTRY xstrConvertLineFormat(PXSTRING pxstr, BOOL fToCFormat);
    156160    typedef VOID XWPENTRY XSTRCONVERTLINEFORMAT(PXSTRING pxstr, BOOL fToCFormat);
  • trunk/src/helpers/except.c

    r31 r32  
    435435                           *(pulStackWord+1));
    436436        pulStackWord = (PULONG)*(pulStackWord);
     437
     438        if (pulStackWord == 0)
     439            fprintf(file, "\n    pulStackWord == 0");
     440        else if (pulStackWord >= (PULONG)ptib->tib_pstacklimit)
     441            fprintf(file, "\n    pulStackWord >= (PULONG)ptib->tib_pstacklimit");
    437442    } // end while
    438443}
     
    736741
    737742            if (ptib != 0)
     743            {
    738744                excDumpStackFrames(file, ptib, pContextRec);
     745            }
    739746        }
    740747    }
  • trunk/src/helpers/xstring.c

    r23 r32  
    390390 *@@changed V0.9.6 (2000-11-01) [umoeller]: rewritten
    391391 *@@changed V0.9.7 (2001-01-15) [umoeller]: added ulSourceLength
     392 *@@changed V0.9.9 (2001-01-28) [lafaix]: fixed memory leak and NULL source behavior
    392393 */
    393394
     
    402403        if (pcszSource)
    403404        {
     405            // source specified:
    404406            if (ulSourceLength == 0)
     407                // but not length:
    405408                ulSourceLength = strlen(pcszSource);
    406 
    407             if (ulSourceLength)
     409        }
     410        else
     411            ulSourceLength = 0;
     412
     413        if (ulSourceLength)
     414        {
     415            // we do have a source string:
     416            ULONG cbNeeded = ulSourceLength + 1;
     417            if (cbNeeded > pxstr->cbAllocated)
    408418            {
    409                 // we do have a source string:
    410                 ULONG cbNeeded = ulSourceLength + 1;
    411                 if (cbNeeded > pxstr->cbAllocated)
    412                 {
    413                     // we need more memory than we have previously
    414                     // allocated:
    415                     pxstr->cbAllocated = cbNeeded;
    416                     pxstr->psz = (PSZ)malloc(cbNeeded);
    417                 }
    418                 // else: we have enough memory
    419 
    420                 // strcpy(pxstr->psz, pcszSource);
    421                 memcpy(pxstr->psz,
    422                        pcszSource,
    423                        ulSourceLength);
    424                 *(pxstr->psz + ulSourceLength) = 0;
     419                // we need more memory than we have previously
     420                // allocated:
     421                if (pxstr->psz)
     422                    free(pxstr->psz); // V0.9.9 (2001-01-28) [lafaix]
     423                pxstr->cbAllocated = cbNeeded;
     424                pxstr->psz = (PSZ)malloc(cbNeeded);
    425425            }
    426             else
    427             {
    428                 // no source specified or source is empty:
    429                 if (pxstr->cbAllocated)
    430                     // we did have a string: set to empty,
    431                     // but leave allocated memory intact
    432                     *(pxstr->psz) = 0;
    433                 // else: pxstr->psz is still NULL
    434             }
    435 
    436             // in all cases, set new length
    437             pxstr->ulLength = ulSourceLength;
     426            // else: we have enough memory
     427
     428            // strcpy(pxstr->psz, pcszSource);
     429            memcpy(pxstr->psz,
     430                   pcszSource,
     431                   ulSourceLength + 1); // V0.9.9 (2001-01-31) [umoeller]
    438432        }
     433        else
     434        {
     435            // no source specified or source is empty:
     436            if (pxstr->cbAllocated)
     437                // we did have a string: set to empty,
     438                // but leave allocated memory intact
     439                *(pxstr->psz) = 0;
     440            // else
     441                // we had no string previously: in that case
     442                // psz and ulLength and cbAllocated are all still NULL
     443        }
     444
     445        // in all cases, set new length
     446        pxstr->ulLength = ulSourceLength;
    439447    }
    440448
     
    627635/*
    628636 *@@ xstrrpl:
    629  *      replaces cSearchLen characters in pxstr, starting
    630  *      at the position ulStart, with the string
     637 *      replaces cReplLen characters in pxstr, starting
     638 *      at the position ulFirstReplPos, with the string
    631639 *      in pxstrReplaceWith.
    632640 *
     
    657665 *
    658666 *@@added V0.9.7 (2001-01-15) [umoeller]
     667 *@@changed V0.9.9 (2001-01-29) [lafaix]: fixed unnecessary allocation when pxstr was big enough
    659668 */
    660669
     
    733742            // we have enough memory left,
    734743            // we can just overwrite in the middle...
    735 
    736             PSZ     pszAfterFoundBackup = 0;
     744            // fixed V0.9.9 (2001-01-29) [lafaix]
     745
    737746            // calc length of string after "found"
    738747            ULONG   cTailLength = pxstr->ulLength - ulFirstReplOfs - cReplLen;
    739748
    740             // if "replace" is longer than "found",
    741             // make a backup of the stuff after "found",
    742             // or this would get overwritten
    743             if (cReplaceLen > cReplLen)
    744             {
    745                 pszAfterFoundBackup = (PSZ)malloc(cTailLength + 1);
    746                 memcpy(pszAfterFoundBackup,
    747                        pFound + cReplLen,
    748                        cTailLength + 1);
    749             }
     749            // first, we move the end to its new location (memmove
     750            // handles overlap if needed)
     751            memmove(pFound + cReplaceLen,
     752                    pFound + cReplLen,
     753                    cTailLength + 1); // including null terminator
    750754
    751755            // now overwrite "found" in the middle
    752756            if (cReplaceLen)
    753757            {
    754                 memcpy(pxstr->psz + ulFirstReplOfs,
     758                memcpy(pFound,
    755759                       pstrReplaceWith->psz,
    756760                       cReplaceLen);        // no null terminator
    757761            }
    758762
    759             // now append tail (stuff after "found") again...
    760             if (pszAfterFoundBackup)
    761             {
    762                 // we made a backup above:
    763                 memcpy(pxstr->psz + ulFirstReplOfs + cReplaceLen,
    764                        pszAfterFoundBackup,
    765                        cTailLength + 1);
    766                 free(pszAfterFoundBackup);
    767                         // done!
    768             }
    769             else
    770                 // no backup:
    771                 if (cReplaceLen < cReplLen)
    772                     // "replace" is shorter than "found:
    773                     memcpy(pxstr->psz + ulFirstReplOfs + cReplaceLen,
    774                            pFound + cReplLen,
    775                            cTailLength + 1);
    776                 // else (cReplaceLen == cReplLen):
    777                 // we can leave the tail as it is
    778 
     763            // that's it; adjust the string length now
    779764            pxstr->ulLength = cbNeeded - 1;
    780765        }
     
    871856 *      (and pxstr was therefore not changed).
    872857 *
    873  *      This starts the search at *pulOffset. If
    874  *      (*pulOffset == 0), this starts from the beginning
     858 *      This starts the search at *pulOfs. If
     859 *      (*pulOfs == 0), this starts from the beginning
    875860 *      of pxstr.
    876861 *
    877  *      If the string was found, *pulOffset will be set to the
     862 *      If the string was found, *pulOfs will be set to the
    878863 *      first character after the new replacement string. This
    879864 *      allows you to call this func again with the same strings
     
    1007992 *      converts between line formats.
    1008993 *
    1009  *      If (fToCFormat == TRUE), all \r\n pairs are replaced
     994 *      If (fToCFormat == CRLF2LF), all \r\n pairs are replaced
    1010995 *      with \n chars (UNIX or C format).
    1011996 *
    1012  *      Reversely, if (fToCFormat == FALSE), all \n chars
     997 *      Reversely, if (fToCFormat == LF2CRLF), all \n chars
    1013998 *      are converted to \r\n pairs (DOS and OS/2 formats).
    1014999 *      No check is made whether this has already been done.
     
    10181003
    10191004VOID xstrConvertLineFormat(PXSTRING pxstr,
    1020                            BOOL fToCFormat) // in: if TRUE, to C format; if FALSE, to OS/2 format.
     1005                           BOOL fToCFormat) // in: if CRLF2LF, to C format; if LF2CRLF, to OS/2 format.
    10211006{
    10221007    XSTRING     strFind,
Note: See TracChangeset for help on using the changeset viewer.