Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 25, 2005, 4:24:50 PM (18 years ago)
Author:
rennerc
Message:

converter: added function which allocates momory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/converter.cc

    r6275 r6285  
    453453  return n+length;
    454454}
     455
     456/**
     457 * reads a string out of a byte array and allocates memory for string
     458 * @param a: byte array
     459 * @param s: string
     460 * @param maxLength: max bytes to copy
     461 * @return: the number of read bytes in byte array
     462 */
     463int Converter::byteArrayToStringM( const byte * a, char * & s )
     464{
     465  int length;
     466
     467  int n = Converter::byteArrayToInt( a, &length );
     468
     469  s = new char[n+1];
     470
     471  if ( !s )
     472  {
     473    PRINTF(1)("Could not allocate memory!\n" );
     474    return -1;
     475  }
     476
     477  memcpy( s, a+n, length );
     478  s[length] = '\0';
     479
     480  return n+length;
     481}
     482
Note: See TracChangeset for help on using the changeset viewer.