Index: trunk/src/stl/string.cc
===================================================================
--- trunk/src/stl/string.cc	(revision 402)
+++ trunk/src/stl/string.cc	(revision 435)
@@ -37,76 +37,96 @@
 }
 
-nv::size_t nv::sint32_to_buffer( sint32 n, char* str )
-{
-	char* s = str;
-	uint32 abs = static_cast< uint32 >( n < 0 ? -n : n );
-	do
-	{
+nv::size_t nv::sint32_to_buffer( array_ref< char > buffer, sint32 n )
+{
+	if ( buffer.size() < 2 ) return 0;
+	char* last = buffer.end() - 1;
+	char* s = buffer.begin();
+	uint32 abs = static_cast<uint32>( n < 0 ? -n : n );
+	do
+	{
+		if ( s == last ) { *buffer.begin() = '\0'; return 0;  }
 		*s++ = static_cast<char>( '0' + ( abs % 10 ) );
 		abs /= 10;
 	} while ( abs > 0 );
-	if ( n < 0 ) *s++ = '-';
-	*s = '\0';
-	string_reverse( str, s - 1 );
-	return static_cast<nv::size_t>( s - str );
-}
-
-nv::size_t nv::sint64_to_buffer( sint64 n, char* str )
-{
-	char* s = str;
-	uint64 abs = static_cast< uint64 >( n < 0 ? -n : n );
-	do
-	{
+	if ( n < 0 )
+	{
+		if ( s == last ) { *buffer.begin() = '\0'; return 0; }
+		*s++ = '-';
+	}
+	*s = '\0';
+	string_reverse( buffer.begin(), s - 1 );
+	return static_cast<nv::size_t>( s - buffer.begin() );
+}
+
+nv::size_t nv::sint64_to_buffer( array_ref< char > buffer, sint64 n )
+{
+	if ( buffer.size() < 2 ) return 0;
+	char* last = buffer.end() - 1;
+	char* s = buffer.begin();
+	uint64 abs = static_cast<uint64>( n < 0 ? -n : n );
+	do
+	{
+		if ( s == last ) { *buffer.begin() = '\0'; return 0; }
 		*s++ = static_cast<char>( '0' + ( abs % 10 ) );
 		abs /= 10;
 	} while ( abs > 0 );
-	if ( n < 0 ) *s++ = '-';
-	*s = '\0';
-	string_reverse( str, s - 1 );
-	return static_cast<nv::size_t>( s - str );
-}
-
-nv::size_t nv::uint32_to_buffer( uint32 n, char* str )
-{
-	char* s = str;
-	do
-	{
+	if ( n < 0 )
+	{
+		if ( s == last ) { *buffer.begin() = '\0'; return 0; }
+		*s++ = '-';
+	}
+	*s = '\0';
+	string_reverse( buffer.begin(), s - 1 );
+	return static_cast<nv::size_t>( s - buffer.begin() );
+}
+
+nv::size_t nv::uint32_to_buffer( array_ref< char > buffer, uint32 n )
+{
+	if ( buffer.size() < 2 ) return 0;
+	char* last = buffer.end() - 1;
+	char* s = buffer.begin();
+	do
+	{
+		if ( s == last ) { *buffer.begin() = '\0'; return 0; }
 		*s++ = static_cast<char>( '0' + ( n % 10 ) );
 		n /= 10;
 	} while ( n > 0 );
 	*s = '\0';
-	string_reverse( str, s - 1 );
-	return static_cast<nv::size_t>( s - str );
-}
-
-nv::size_t nv::uint64_to_buffer( uint64 n, char* str )
-{
-	char* s = str;
-	do
-	{
+	string_reverse( buffer.begin(), s - 1 );
+	return static_cast<nv::size_t>( s - buffer.begin() );
+}
+
+nv::size_t nv::uint64_to_buffer( array_ref< char > buffer, uint64 n )
+{
+	if ( buffer.size() < 2 ) return 0;
+	char* last = buffer.end() - 1;
+	char* s = buffer.begin();
+	do
+	{
+		if ( s == last ) { *buffer.begin() = '\0'; return 0; }
 		*s++ = static_cast<char>( '0' + ( n % 10 ) );
 		n /= 10;
 	} while ( n > 0 );
 	*s = '\0';
-	string_reverse( str, s - 1 );
-	return static_cast<nv::size_t>( s - str );
-}
-
-nv::size_t nv::f32_to_buffer( f32 n, char* str )
+	string_reverse( buffer.begin(), s - 1 );
+	return static_cast<nv::size_t>( s - buffer.begin() );
+}
+
+nv::size_t nv::f32_to_buffer( array_ref< char > buffer, f32 n )
 {
 #if NV_COMPILER == NV_MSVC
-	int result = sprintf_s( str, 64, "%.*g", 6, n );
+	int result = sprintf_s( buffer.data(), buffer.size(), "%.*g", 6, n );
 #else
-	int result = snprintf( str, 64, "%.*g", 6, n );
+	int result = snprintf( buffer.data(), buffer.size(), "%.*g", 6, n );
 #endif
 	return static_cast<nv::size_t>( result > 0 ? result : 0 );
 }
 
-nv::size_t nv::f64_to_buffer( f64 n, char* str )
+nv::size_t nv::f64_to_buffer( array_ref< char > buffer, f64 n )
 {
 #if NV_COMPILER == NV_MSVC
-	int result = sprintf_s( str, 64, "%.*g", 6, n );
+	int result = sprintf_s( buffer.data(), buffer.size(), "%.*g", 6, n );
 #else
-	int result = snprintf( str, 64, "%.*g", 6, n );
+	int result = snprintf( buffer.data(), buffer.size(), "%.*g", 6, n );
 #endif
 	return static_cast<nv::size_t>( result > 0 ? result : 0 );
