Ignore:
Timestamp:
Nov 21, 2000, 3:10:09 PM (25 years ago)
Author:
sandervl
Message:

lstrcpynAtoW/WtoA bugfix (string termination)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/heapstring.cpp

    r4525 r4664  
    1 /* $Id: heapstring.cpp,v 1.34 2000-10-23 19:35:11 sandervl Exp $ */
     1/* $Id: heapstring.cpp,v 1.35 2000-11-21 14:10:08 sandervl Exp $ */
    22
    33/*
     
    547547    for (i = 0; i < unilen-1; i++)
    548548    {
    549       astring[i] = (ustring[i] > 255) ? (char)20 : (char)ustring[i]; //CB: handle invalid characters as space
     549      astring[i] = (ustring[i] > 255) ? (char)0x20 : (char)ustring[i]; //CB: handle invalid characters as space
    550550      if (ustring[i] == 0) return i; //asta la vista, baby
    551551    }
    552552
    553     astring[unilen-1] = 0; // @@@PH: 1999/06/09 fix - always terminate string
    554 
    555     return(unilen-1);
     553//    astring[unilen-1] = 0; // @@@PH: 1999/06/09 fix - always terminate string
     554//    return(unilen-1);
     555    return unilen;
    556556  }
    557557}
     
    566566
    567567    ret = lstrcpynCtoA(astring, ustring, unilen, GetWindowsUconvObject());
    568     astring[unilen-1] = 0;
     568    //Must not always set the last character to 0; some apps send the wrong
     569    //string size to apis that use this function (i.e. GetMenuStringW (Notes))
     570    //-> overwrites stack
     571    if(ret == unilen) {
     572         astring[unilen-1] = 0;
     573    }
     574    else astring[ret] = 0;
     575   
    569576    return ret;
    570577}
     
    680687
    681688    ret = lstrcpynAtoC(unicode, ascii, asciilen, GetWindowsUconvObject());
    682     unicode[asciilen-1] = 0;
     689    //Must not always set the last character to 0; some apps send the wrong
     690    //string size to apis that use this function (i.e. GetMenuStringW (Notes))
     691    //-> overwrites stack
     692    if(ret == asciilen) {
     693         unicode[asciilen-1] = 0;
     694    }
     695    else unicode[ret] = 0;
    683696    return ret;
    684697}
Note: See TracChangeset for help on using the changeset viewer.