]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Wrap some buffers
authorTimePath <andrew.hardaker1995@gmail.com>
Tue, 8 Aug 2017 11:14:47 +0000 (21:14 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Tue, 8 Aug 2017 11:14:47 +0000 (21:14 +1000)
27 files changed:
include/itextstream.h
libs/CMakeLists.txt
libs/util/CMakeLists.txt [new file with mode: 0644]
libs/util/buffer.cpp [new file with mode: 0644]
libs/util/buffer.h [new file with mode: 0644]
radiant/brushxml.h
radiant/commands.cpp
radiant/eclass.cpp
radiant/eclass_def.cpp
radiant/entity.cpp
radiant/entityinspector.cpp
radiant/environment.cpp
radiant/error.cpp
radiant/filetypes.cpp
radiant/gtkdlgs.cpp
radiant/main.cpp
radiant/mainframe.cpp
radiant/map.cpp
radiant/mru.cpp
radiant/patch.h
radiant/patchdialog.cpp
radiant/qe3.cpp
radiant/textures.cpp
radiant/texwindow.cpp
radiant/view.cpp
radiant/watchbsp.cpp
radiant/xywindow.cpp

index 7d69c7b5ae3372986031249b296f9ab2cbcde38d..73fd074cba736c2709c0317fafd94865ba320902 100644 (file)
@@ -26,6 +26,7 @@
 /// \brief Text-stream interfaces.
 
 #include <cstddef>
 /// \brief Text-stream interfaces.
 
 #include <cstddef>
+#include <util/buffer.h>
 #include "generic/static.h"
 
 /// \brief A read-only character-stream.
 #include "generic/static.h"
 
 /// \brief A read-only character-stream.
@@ -65,6 +66,10 @@ inline TextOutputStream& operator<<( TextOutputStream& ostream, const T& t ){
        return ostream_write( ostream, t );
 }
 
        return ostream_write( ostream, t );
 }
 
+inline TextOutputStream& ostream_write( TextOutputStream& ostream, const u::Buffer& b ){
+    return ostream << b.c_str();
+}
+
 class NullOutputStream : public TextOutputStream
 {
 public:
 class NullOutputStream : public TextOutputStream
 {
 public:
index 03347d71ef0bd894feda504f140205f2caa66991..c7e01f939511e6b33e26ead9df290758f4478019 100644 (file)
@@ -22,6 +22,7 @@ add_subdirectory(splines)
 add_subdirectory(stream)
 add_subdirectory(string)
 add_subdirectory(uilib)
 add_subdirectory(stream)
 add_subdirectory(string)
 add_subdirectory(uilib)
+add_subdirectory(util)
 add_subdirectory(xml)
 
 add_library(libs
 add_subdirectory(xml)
 
 add_library(libs
diff --git a/libs/util/CMakeLists.txt b/libs/util/CMakeLists.txt
new file mode 100644 (file)
index 0000000..7a89b6e
--- /dev/null
@@ -0,0 +1,3 @@
+add_library(util
+        buffer.cpp
+        )
diff --git a/libs/util/buffer.cpp b/libs/util/buffer.cpp
new file mode 100644 (file)
index 0000000..113a800
--- /dev/null
@@ -0,0 +1 @@
+#include "buffer.h"
diff --git a/libs/util/buffer.h b/libs/util/buffer.h
new file mode 100644 (file)
index 0000000..9ce31d6
--- /dev/null
@@ -0,0 +1,79 @@
+#ifndef INCLUDED_BUFFER_H
+#define INCLUDED_BUFFER_H
+
+namespace u {
+
+    using byte = char;
+
+    using cstring = const char *;
+
+    namespace details {
+        struct Reference {
+        private:
+            int m_size;
+            byte *m_data;
+        public:
+            Reference(int m_size, byte *m_data)
+                    : m_size(m_size), m_data(m_data) {}
+
+            int size() const {
+                return m_size;
+            }
+
+            const byte *data() const {
+                return m_data;
+            }
+
+            byte *data() {
+                return m_data;
+            }
+        };
+
+        template<int sz>
+        struct Value {
+            byte m_data[sz];
+
+            int size() const {
+                return sz;
+            }
+
+            const byte *data() const {
+                return m_data;
+            }
+
+            byte *data() {
+                return m_data;
+            }
+        };
+    }
+
+    template<class Self>
+    class IBuffer : Self {
+        using Self::Self;
+    public:
+        operator const IBuffer<details::Reference>() const {
+            return IBuffer<details::Reference>{this->size(), const_cast<byte *>(this->data())};
+        }
+
+        cstring c_str() const {
+            return this->data();
+        }
+
+        operator byte *() {
+            return this->data();
+        }
+    };
+
+    template<int sz>
+    using BufferVal = IBuffer<details::Value<sz>>;
+
+    using Buffer = IBuffer<details::Reference>;
+
+    template<int sz>
+    BufferVal<sz> buffer() {
+        return BufferVal<sz>();
+    }
+
+}
+
+#endif
index c1fac55bccc0cdaced23d17a5cb3ebc5a9b0e590..d312591cc492b56d1778f471c3784d268330fcbd 100644 (file)
@@ -22,6 +22,7 @@
 #if !defined( INCLUDED_BRUSHXML_H )
 #define INCLUDED_BRUSHXML_H
 
 #if !defined( INCLUDED_BRUSHXML_H )
 #define INCLUDED_BRUSHXML_H
 
+#include <util/buffer.h>
 #include "stream/stringstream.h"
 #include "xml/xmlelement.h"
 
 #include "stream/stringstream.h"
 #include "xml/xmlelement.h"
 
@@ -233,7 +234,7 @@ inline void FacePlane_exportXML( const FacePlane& facePlane, XMLImporter& import
 inline void FacePolygon_exportXML( const Winding& w, const BasicVector3<double>& normal, XMLImporter& importer ){
        DynamicElement element( "polygon" );
 
 inline void FacePolygon_exportXML( const Winding& w, const BasicVector3<double>& normal, XMLImporter& importer ){
        DynamicElement element( "polygon" );
 
-       char tmp[32];
+       auto tmp = u::buffer<32>();
 
        sprintf( tmp, "%f", normal.x() );
        element.insertAttribute( "nx", tmp );
 
        sprintf( tmp, "%f", normal.x() );
        element.insertAttribute( "nx", tmp );
index cf9c68ce8c3efad75fd5299a0377751da70ec403..06dc7575cb502bccff62c2cab2d861dec8e29108 100644 (file)
@@ -150,6 +150,7 @@ void connect_accelerator( const char *name ){
 
 #include <uilib/uilib.h>
 #include <gdk/gdkkeysyms.h>
 
 #include <uilib/uilib.h>
 #include <gdk/gdkkeysyms.h>
+#include <util/buffer.h>
 
 #include "gtkutil/dialog.h"
 #include "mainframe.h"
 
 #include "gtkutil/dialog.h"
 #include "mainframe.h"
@@ -537,7 +538,7 @@ public:
 ReadCommandMap( const char* filename ) : m_filename( filename ), m_count( 0 ){
 }
 void visit( const char* name, Accelerator& accelerator ){
 ReadCommandMap( const char* filename ) : m_filename( filename ), m_count( 0 ){
 }
 void visit( const char* name, Accelerator& accelerator ){
-       char value[1024];
+       auto value = u::buffer<1024>();
        if ( read_var( m_filename, "Commands", name, value ) ) {
                if ( string_empty( value ) ) {
                        accelerator.key = 0;
        if ( read_var( m_filename, "Commands", name, value ) ) {
                if ( string_empty( value ) ) {
                        accelerator.key = 0;
@@ -575,7 +576,7 @@ void LoadCommandMap( const char* path ){
                Version dataVersion = { 0, 0 };
 
                {
                Version dataVersion = { 0, 0 };
 
                {
-                       char value[1024];
+                       auto value = u::buffer<1024>();
                        if ( read_var( strINI.c_str(), "Version", "number", value ) ) {
                                dataVersion = version_parse( value );
                        }
                        if ( read_var( strINI.c_str(), "Version", "number", value ) ) {
                                dataVersion = version_parse( value );
                        }
index ea9828e510857749ebe09e3a0eacee48f19f1c2a..892a2ddecae801d0e82d387fd2552129021d6d66 100644 (file)
@@ -24,6 +24,7 @@
 #include "debugging/debugging.h"
 
 #include <map>
 #include "debugging/debugging.h"
 
 #include <map>
+#include <util/buffer.h>
 
 #include "ifilesystem.h"
 
 
 #include "ifilesystem.h"
 
@@ -45,7 +46,7 @@ namespace
 typedef std::map<const char*, EntityClass*, RawStringLessNoCase> EntityClasses;
 EntityClasses g_entityClasses;
 EntityClass   *eclass_bad = 0;
 typedef std::map<const char*, EntityClass*, RawStringLessNoCase> EntityClasses;
 EntityClasses g_entityClasses;
 EntityClass   *eclass_bad = 0;
-char eclass_directory[1024];
+u::BufferVal<1024> eclass_directory;
 typedef std::map<CopiedString, ListAttributeType> ListAttributeTypes;
 ListAttributeTypes g_listTypes;
 }
 typedef std::map<CopiedString, ListAttributeType> ListAttributeTypes;
 ListAttributeTypes g_listTypes;
 }
index 8637b4800c186e1ff3c23d260fe904779ca4fc7f..a619ed74d0f7e8df6894e2f62a00828591564ec8 100644 (file)
@@ -30,6 +30,7 @@
 #include "stream/textfilestream.h"
 #include "modulesystem/moduleregistry.h"
 #include "os/path.h"
 #include "stream/textfilestream.h"
 #include "modulesystem/moduleregistry.h"
 #include "os/path.h"
+#include <util/buffer.h>
 
 const char* EClass_GetExtension(){
        return "def";
 
 const char* EClass_GetExtension(){
        return "def";
@@ -69,7 +70,7 @@ StaticRegisterModule staticRegisterEclassDef( StaticEclassDefModule::instance()
 #include <stdlib.h>
 
 
 #include <stdlib.h>
 
 
-char com_token[1024];
+u::BufferVal<1024> com_token;
 bool com_eof;
 
 /*
 bool com_eof;
 
 /*
@@ -248,7 +249,7 @@ EntityClass *Eclass_InitFromText( const char *text ){
                }
        }
 
                }
        }
 
-       char parms[256];
+       auto parms = u::buffer<256>();
        // get the flags
        {
                // copy to the first /n
        // get the flags
        {
                // copy to the first /n
index cf726aca2243293b42d489e9c261b0e5ef92eca6..87cf9cd0158a872b474d3355fe125d8a649edeea 100644 (file)
@@ -19,6 +19,7 @@
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <util/buffer.h>
 #include "entity.h"
 
 #include "ientity.h"
 #include "entity.h"
 
 #include "ientity.h"
@@ -354,7 +355,7 @@ void Entity_createFromSelection( const char* name, const Vector3& origin ){
 
                        if ( DoLightIntensityDlg( &intensity ) == eIDOK ) {
                                g_iLastLightIntensity = intensity;
 
                        if ( DoLightIntensityDlg( &intensity ) == eIDOK ) {
                                g_iLastLightIntensity = intensity;
-                               char buf[30];
+                               auto buf = u::buffer<30>();
                                sprintf( buf, "255 255 255 %d", intensity );
                                Node_getEntity( node )->setKeyValue( "_light", buf );
                        }
                                sprintf( buf, "255 255 255 %d", intensity );
                                Node_getEntity( node )->setKeyValue( "_light", buf );
                        }
@@ -366,7 +367,7 @@ void Entity_createFromSelection( const char* name, const Vector3& origin ){
 
                        if ( DoLightIntensityDlg( &intensity ) == eIDOK ) {
                                g_iLastLightIntensity = intensity;
 
                        if ( DoLightIntensityDlg( &intensity ) == eIDOK ) {
                                g_iLastLightIntensity = intensity;
-                               char buf[10];
+                               auto buf = u::buffer<10>();
                                sprintf( buf, "%d", intensity );
                                Node_getEntity( node )->setKeyValue( "light", buf );
                        }
                                sprintf( buf, "%d", intensity );
                                Node_getEntity( node )->setKeyValue( "light", buf );
                        }
@@ -472,7 +473,7 @@ void Entity_normalizeColor(){
                                        g_entity_globals.color_entity = rgb;
                                        NormalizeColor( g_entity_globals.color_entity );
 
                                        g_entity_globals.color_entity = rgb;
                                        NormalizeColor( g_entity_globals.color_entity );
 
-                                       char buffer[128];
+                                       auto buffer = u::buffer<128>();
                                        sprintf( buffer, "%g %g %g", g_entity_globals.color_entity[0],
                                                         g_entity_globals.color_entity[1],
                                                         g_entity_globals.color_entity[2] );
                                        sprintf( buffer, "%g %g %g", g_entity_globals.color_entity[0],
                                                         g_entity_globals.color_entity[1],
                                                         g_entity_globals.color_entity[2] );
@@ -508,7 +509,7 @@ void Entity_setColour(){
                                        NormalizeColor( g_entity_globals.color_entity );
                                }
 
                                        NormalizeColor( g_entity_globals.color_entity );
                                }
 
-                               char buffer[128];
+                               auto buffer = u::buffer<128>();
                                sprintf( buffer, "%g %g %g", g_entity_globals.color_entity[0],
                                                 g_entity_globals.color_entity[1],
                                                 g_entity_globals.color_entity[2] );
                                sprintf( buffer, "%g %g %g", g_entity_globals.color_entity[0],
                                                 g_entity_globals.color_entity[1],
                                                 g_entity_globals.color_entity[2] );
index ff56706001126681a42a49c2b7e6b4dc4d4110e9..1e6b5d06c8ac8d42a480ec08bc52834a2e481cbc 100644 (file)
@@ -35,6 +35,7 @@
 #include <set>
 #include <gdk/gdkkeysyms.h>
 #include <uilib/uilib.h>
 #include <set>
 #include <gdk/gdkkeysyms.h>
 #include <uilib/uilib.h>
+#include <util/buffer.h>
 
 
 #include "os/path.h"
 
 
 #include "os/path.h"
@@ -1005,7 +1006,7 @@ void EntityInspector_updateSpawnflags(){
 
 void EntityInspector_applySpawnflags(){
        int f, i, v;
 
 void EntityInspector_applySpawnflags(){
        int f, i, v;
-       char sz[32];
+       auto sz = u::buffer<32>();
 
        f = 0;
        for ( i = 0; i < g_spawnflag_count; ++i )
 
        f = 0;
        for ( i = 0; i < g_spawnflag_count; ++i )
index a91b109b39e9914d07ac5a15605f9a6eb474307b..0d5c243ad73e5cab330b53affa3dcd86d284a509 100644 (file)
@@ -19,6 +19,7 @@
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <util/buffer.h>
 #include "environment.h"
 
 #include "stream/textstream.h"
 #include "environment.h"
 
 #include "stream/textstream.h"
@@ -57,7 +58,7 @@ void args_init( int argc, const char* argv[] ){
 const char *gamedetect_argv_buffer[1024];
 void gamedetect_found_game( const char *game, char *path ){
        int argc;
 const char *gamedetect_argv_buffer[1024];
 void gamedetect_found_game( const char *game, char *path ){
        int argc;
-       static char buf[128];
+       static auto buf = u::buffer<128>();
 
        if ( g_argv == gamedetect_argv_buffer ) {
                return;
 
        if ( g_argv == gamedetect_argv_buffer ) {
                return;
@@ -114,7 +115,7 @@ void gamedetect(){
                        ++i;
                }
        if ( !nogamedetect ) {
                        ++i;
                }
        if ( !nogamedetect ) {
-               static char buf[1024 + 64];
+               static auto buf = u::buffer<1024 + 64>();
                strncpy( buf, environment_get_app_path(), sizeof( buf ) );
                buf[sizeof( buf ) - 1 - 64] = 0;
                if ( !strlen( buf ) ) {
                strncpy( buf, environment_get_app_path(), sizeof( buf ) );
                buf[sizeof( buf ) - 1 - 64] = 0;
                if ( !strlen( buf ) ) {
@@ -261,7 +262,7 @@ void environment_init( int argc, const char* argv[] ){
 
        {
                // get path to the editor
 
        {
                // get path to the editor
-               char filename[MAX_PATH + 1];
+               auto filename = u::buffer<MAX_PATH + 1>();
                GetModuleFileName( 0, filename, MAX_PATH );
                char* last_separator = strrchr( filename, '\\' );
                if ( last_separator != 0 ) {
                GetModuleFileName( 0, filename, MAX_PATH );
                char* last_separator = strrchr( filename, '\\' );
                if ( last_separator != 0 ) {
index fda7f79f8361fbc32619bd2d289b0173090076ad..56a8a056d6bee05ad7ef253bdbd0f6d51c397cbb 100644 (file)
@@ -35,6 +35,8 @@
 #else
 #include <errno.h>
 #include <unistd.h>
 #else
 #include <errno.h>
 #include <unistd.h>
+#include <util/buffer.h>
+
 #endif
 
 
 #endif
 
 
@@ -55,7 +57,7 @@
 
 void Error( const char *error, ... ){
        va_list argptr;
 
 void Error( const char *error, ... ){
        va_list argptr;
-       char text[4096];
+       auto text = u::buffer<4096>();
 
        va_start( argptr,error );
        vsprintf( text, error,argptr );
 
        va_start( argptr,error );
        vsprintf( text, error,argptr );
index 6a08cecd8c63a3afe63ff54a12cb7c869705435e..115b1e2601808cd23c561a1330f40c9d2c76df45 100644 (file)
@@ -29,6 +29,7 @@
 #include "os/path.h"
 #include <vector>
 #include <map>
 #include "os/path.h"
 #include <vector>
 #include <map>
+#include <util/buffer.h>
 
 class RadiantFileTypeRegistry : public IFileTypeRegistry
 {
 
 class RadiantFileTypeRegistry : public IFileTypeRegistry
 {
@@ -87,7 +88,7 @@ IFileTypeRegistry* GetFileTypeRegistry(){
 const char* findModuleName( IFileTypeRegistry* registry, const char* moduleType, const char* extension ){
        class SearchFileTypeList : public IFileTypeList
        {
 const char* findModuleName( IFileTypeRegistry* registry, const char* moduleType, const char* extension ){
        class SearchFileTypeList : public IFileTypeList
        {
-       char m_pattern[128];
+       u::BufferVal<128> m_pattern;
        const char* m_moduleName;
 public:
        SearchFileTypeList( const char* ext )
        const char* m_moduleName;
 public:
        SearchFileTypeList( const char* ext )
index fe547435b6c020c4cf23b5b53330e6658a13081d..3486c1ba883c9abe24b35ea136587cc6276b6bb4 100644 (file)
@@ -48,6 +48,7 @@
 
 #include <gdk/gdkkeysyms.h>
 #include <uilib/uilib.h>
 
 #include <gdk/gdkkeysyms.h>
 #include <uilib/uilib.h>
+#include <util/buffer.h>
 
 #include "os/path.h"
 #include "math/aabb.h"
 
 #include "os/path.h"
 #include "math/aabb.h"
@@ -675,8 +676,8 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){
        }
        
        // Initialize with last used values
        }
        
        // Initialize with last used values
-       char buf[16];
-       
+       auto buf = u::buffer<16>();
+
        sprintf( buf, "%f", last_used_texture_layout_scale_x );
        x.text( buf );
        
        sprintf( buf, "%f", last_used_texture_layout_scale_x );
        x.text( buf );
        
@@ -899,7 +900,7 @@ EMessageBoxReturn DoLightIntensityDlg( int *intensity ){
                }
        }
 
                }
        }
 
-       char buf[16];
+       auto buf = u::buffer<16>();
        sprintf( buf, "%d", *intensity );
        intensity_entry.text(buf);
 
        sprintf( buf, "%d", *intensity );
        intensity_entry.text(buf);
 
index 74ddce1f2b99dd01dd02b01cdf242dcec6a96d6c..270e8a5a2d17d7d9d4ef8a5d27a0b5517a1868db 100644 (file)
@@ -89,6 +89,8 @@
 #include "referencecache.h"
 #include "stacktrace.h"
 
 #include "referencecache.h"
 #include "stacktrace.h"
 
+#include <util/buffer.h>
+
 #ifdef WIN32
 #include <windows.h>
 #endif
 #ifdef WIN32
 #include <windows.h>
 #endif
@@ -99,7 +101,7 @@ void hide_splash();
 void error_redirect( const gchar *domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data ){
        gboolean in_recursion;
        gboolean is_fatal;
 void error_redirect( const gchar *domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data ){
        gboolean in_recursion;
        gboolean is_fatal;
-       char buf[256];
+       auto buf = u::buffer<256>();
 
        in_recursion = ( log_level & G_LOG_FLAG_RECURSION ) != 0;
        is_fatal = ( log_level & G_LOG_FLAG_FATAL ) != 0;
 
        in_recursion = ( log_level & G_LOG_FLAG_RECURSION ) != 0;
        is_fatal = ( log_level & G_LOG_FLAG_FATAL ) != 0;
@@ -347,7 +349,7 @@ void paths_init(){
 bool check_version_file( const char* filename, const char* version ){
        TextFileInputStream file( filename );
        if ( !file.failed() ) {
 bool check_version_file( const char* filename, const char* version ){
        TextFileInputStream file( filename );
        if ( !file.failed() ) {
-               char buf[10];
+               auto buf = u::buffer<10>();
                buf[file.read( buf, 9 )] = '\0';
 
                // chomp it (the hard way)
                buf[file.read( buf, 9 )] = '\0';
 
                // chomp it (the hard way)
index b54ff8277f8344d536b75bd934e8d00342769c82..02c8c9b3a31a2befb17d0ca3add0a17f1b68ccf1 100644 (file)
@@ -40,6 +40,7 @@
 #include <ctime>
 
 #include <gdk/gdkkeysyms.h>
 #include <ctime>
 
 #include <gdk/gdkkeysyms.h>
+#include <util/buffer.h>
 
 
 #include "cmdlib.h"
 
 
 #include "cmdlib.h"
@@ -527,7 +528,7 @@ public:
 CLoadModule( const char* path ) : m_path( path ){
 }
 void operator()( const char* name ) const {
 CLoadModule( const char* path ) : m_path( path ){
 }
 void operator()( const char* name ) const {
-       char fullname[1024];
+       auto fullname = u::buffer<1024>();
        ASSERT_MESSAGE( strlen( m_path ) + strlen( name ) < 1024, "" );
        strcpy( fullname, m_path );
        strcat( fullname, name );
        ASSERT_MESSAGE( strlen( m_path ) + strlen( name ) < 1024, "" );
        strcpy( fullname, m_path );
        strcat( fullname, name );
index 33dcebe9a51a79301430ad559015486f421fe331..2f42496f8421db5f9abb2d5ac0c0aee7a60c63ae 100644 (file)
@@ -45,6 +45,7 @@ MapModules& ReferenceAPI_getMapModules();
 #include <set>
 
 #include <gdk/gdkkeysyms.h>
 #include <set>
 
 #include <gdk/gdkkeysyms.h>
+#include <util/buffer.h>
 #include "uilib/uilib.h"
 
 #include "scenelib.h"
 #include "uilib/uilib.h"
 
 #include "scenelib.h"
@@ -151,7 +152,7 @@ void detach( const NameCallback& setName, const NameCallbackCallback& detachObse
 }
 
 void makeUnique( const char* name, const NameCallback& setName ) const {
 }
 
 void makeUnique( const char* name, const NameCallback& setName ) const {
-       char buffer[1024];
+       auto buffer = u::buffer<1024>();
        name_write( buffer, m_uniqueNames.make_unique( name_read( name ) ) );
        setName( buffer );
 }
        name_write( buffer, m_uniqueNames.make_unique( name_read( name ) ) );
        setName( buffer );
 }
@@ -173,7 +174,7 @@ void mergeNames( const BasicNamespace& other ) const {
                name_t uniqueName( uniqueNames.make_unique( name_read( ( *i ).first.c_str() ) ) );
                uniqueNames.insert( uniqueName );
 
                name_t uniqueName( uniqueNames.make_unique( name_read( ( *i ).first.c_str() ) ) );
                uniqueNames.insert( uniqueName );
 
-               char buffer[1024];
+               auto buffer = u::buffer<1024>();
                name_write( buffer, uniqueName );
 
                //globalOutputStream() << "renaming " << makeQuoted((*i).first.c_str()) << " to " << makeQuoted(buffer) << "\n";
                name_write( buffer, uniqueName );
 
                //globalOutputStream() << "renaming " << makeQuoted((*i).first.c_str()) << " to " << makeQuoted(buffer) << "\n";
@@ -877,7 +878,7 @@ void DoMapInfo(){
 
                for ( EntityBreakdown::iterator i = entitymap.begin(); i != entitymap.end(); ++i )
                {
 
                for ( EntityBreakdown::iterator i = entitymap.begin(); i != entitymap.end(); ++i )
                {
-                       char tmp[16];
+                       auto tmp = u::buffer<16>();
                        sprintf( tmp, "%u", Unsigned( ( *i ).second ) );
                        GtkTreeIter iter;
                        gtk_list_store_append( GTK_LIST_STORE( EntityBreakdownWalker ), &iter );
                        sprintf( tmp, "%u", Unsigned( ( *i ).second ) );
                        GtkTreeIter iter;
                        gtk_list_store_append( GTK_LIST_STORE( EntityBreakdownWalker ), &iter );
@@ -887,7 +888,7 @@ void DoMapInfo(){
 
        EntityBreakdownWalker.unref();
 
 
        EntityBreakdownWalker.unref();
 
-       char tmp[16];
+       auto tmp = u::buffer<16>();
        sprintf( tmp, "%u", Unsigned( g_brushCount.get() ) );
        brushes_entry.text(tmp);
        sprintf( tmp, "%u", Unsigned( g_entityCount.get() ) );
        sprintf( tmp, "%u", Unsigned( g_brushCount.get() ) );
        brushes_entry.text(tmp);
        sprintf( tmp, "%u", Unsigned( g_entityCount.get() ) );
@@ -1267,7 +1268,7 @@ void ConstructRegionStartpoint( scene::Node* startpoint, const Vector3& region_m
        }
 
        // write the info_playerstart
        }
 
        // write the info_playerstart
-       char sTmp[1024];
+       auto sTmp = u::buffer<1024>();
        sprintf( sTmp, "%d %d %d", (int)vOrig[0], (int)vOrig[1], (int)vOrig[2] );
        Node_getEntity( *startpoint )->setKeyValue( "origin", sTmp );
        sprintf( sTmp, "%d", (int)Camera_getAngles( *g_pParentWnd->GetCamWnd() )[CAMERA_YAW] );
        sprintf( sTmp, "%d %d %d", (int)vOrig[0], (int)vOrig[1], (int)vOrig[2] );
        Node_getEntity( *startpoint )->setKeyValue( "origin", sTmp );
        sprintf( sTmp, "%d", (int)Camera_getAngles( *g_pParentWnd->GetCamWnd() )[CAMERA_YAW] );
@@ -2101,7 +2102,7 @@ void DoFind(){
        }
 
        // Initialize dialog
        }
 
        // Initialize dialog
-       char buf[16];
+       auto buf = u::buffer<16>();
        int ent, br;
 
        GetSelectionIndex( &ent, &br );
        int ent, br;
 
        GetSelectionIndex( &ent, &br );
index 3a01d142ef7297069db4e5870d595693672081ee..916ea8422bf080c2d09625e0392b9a0c66d76804 100644 (file)
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <gtk/gtk.h>
 #include <string.h>
 #include <stdio.h>
 #include <gtk/gtk.h>
+#include <util/buffer.h>
 
 #include "os/file.h"
 #include "generic/callback.h"
 
 #include "os/file.h"
 #include "generic/callback.h"
@@ -142,7 +143,7 @@ void MRU_AddWidget( GtkMenuItem *widget, std::size_t pos ){
 }
 
 void MRU_Activate( std::size_t index ){
 }
 
 void MRU_Activate( std::size_t index ){
-       char text[1024];
+       auto text = u::buffer<1024>();
        strcpy( text, MRU_GetText( index ) );
 
        if ( file_readable( text ) ) { //\todo Test 'map load succeeds' instead of 'file is readable'.
        strcpy( text, MRU_GetText( index ) );
 
        if ( file_readable( text ) ) { //\todo Test 'map load succeeds' instead of 'file is readable'.
index a1f1d272a20a682bb987337d12f8f481925d787b..bc98fabe40bb75f0df475f0ada0b52c2c69c7f75 100644 (file)
@@ -44,6 +44,7 @@
 
 #include <set>
 #include <limits>
 
 #include <set>
 #include <limits>
+#include <util/buffer.h>
 
 #include "math/frustum.h"
 #include "string/string.h"
 
 #include "math/frustum.h"
 #include "string/string.h"
@@ -803,7 +804,8 @@ void exportXML( XMLImporter& importer ){
        }
 
        {
        }
 
        {
-               char width[16], height[16];
+               auto width = u::buffer<16>();
+               auto height = u::buffer<16>();
                sprintf( width, "%u", Unsigned( m_width ) );
                sprintf( height, "%u", Unsigned( m_height ) );
                StaticElement element( "matrix" );
                sprintf( width, "%u", Unsigned( m_width ) );
                sprintf( height, "%u", Unsigned( m_height ) );
                StaticElement element( "matrix" );
index da5e2283023c4c24e6a0ee742783ba56a03141d7..7c1e63a42b36fdbc505a9d294086d9129c2d770b 100644 (file)
@@ -1079,7 +1079,7 @@ void PatchInspector::GetPatchInfo(){
                        m_countRows = m_Patch->getHeight();
                        for ( std::size_t i = 0; i < m_countRows; ++i )
                        {
                        m_countRows = m_Patch->getHeight();
                        for ( std::size_t i = 0; i < m_countRows; ++i )
                        {
-                               char buffer[16];
+                               auto buffer = u::buffer<16>();
                                sprintf( buffer, "%u", Unsigned( i ) );
                                gtk_combo_box_text_append_text( m_pRowCombo, buffer );
                        }
                                sprintf( buffer, "%u", Unsigned( i ) );
                                gtk_combo_box_text_append_text( m_pRowCombo, buffer );
                        }
@@ -1098,7 +1098,7 @@ void PatchInspector::GetPatchInfo(){
                        m_countCols = m_Patch->getWidth();
                        for ( std::size_t i = 0; i < m_countCols; ++i )
                        {
                        m_countCols = m_Patch->getWidth();
                        for ( std::size_t i = 0; i < m_countCols; ++i )
                        {
-                               char buffer[16];
+                               auto buffer = u::buffer<16>();
                                sprintf( buffer, "%u", Unsigned( i ) );
                                gtk_combo_box_text_append_text( m_pColCombo, buffer );
                        }
                                sprintf( buffer, "%u", Unsigned( i ) );
                                gtk_combo_box_text_append_text( m_pColCombo, buffer );
                        }
index 7d685bae3465b5152f82114afa28adcdc9c93ac7..717c3c844727eaa398827b8d7118a5bf460e7563 100644 (file)
@@ -44,6 +44,7 @@
 #include <map>
 
 #include <uilib/uilib.h>
 #include <map>
 
 #include <uilib/uilib.h>
+#include <util/buffer.h>
 
 #include "stream/textfilestream.h"
 #include "cmdlib.h"
 
 #include "stream/textfilestream.h"
 #include "cmdlib.h"
@@ -118,7 +119,7 @@ int g_numbrushes = 0;
 int g_numentities = 0;
 
 void QE_UpdateStatusBar(){
 int g_numentities = 0;
 
 void QE_UpdateStatusBar(){
-       char buffer[128];
+       auto buffer = u::buffer<128>();
        sprintf( buffer, "Brushes: %d Entities: %d", g_numbrushes, g_numentities );
        g_pParentWnd->SetStatusText( g_pParentWnd->m_brushcount_status, buffer );
 }
        sprintf( buffer, "Brushes: %d Entities: %d", g_numbrushes, g_numentities );
        g_pParentWnd->SetStatusText( g_pParentWnd->m_brushcount_status, buffer );
 }
index 93ce42a8cdbec549f21f9b64926896c5f357d650..3b96fbbf59ef600eee2926745c1ca58aeab1456d 100644 (file)
@@ -19,6 +19,7 @@
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <util/buffer.h>
 #include "textures.h"
 
 #include "debugging/debugging.h"
 #include "textures.h"
 
 #include "debugging/debugging.h"
@@ -137,7 +138,7 @@ ETexturesMode g_texture_mode = eTextures_LINEAR_MIPMAP_LINEAR;
 
 
 
 
 
 
-byte g_gammatable[256];
+u::BufferVal<256> g_gammatable;
 void ResampleGamma( float fGamma ){
        int i,inf;
        if ( fGamma == 1.0 ) {
 void ResampleGamma( float fGamma ){
        int i,inf;
        if ( fGamma == 1.0 ) {
@@ -274,7 +275,7 @@ void Texture_InitPalette( byte *pal ){
        int r,g,b;
        int i;
        int inf;
        int r,g,b;
        int i;
        int inf;
-       byte gammatable[256];
+       auto gammatable = u::buffer<256>();
        float gamma;
 
        gamma = g_texture_globals.fGamma;
        float gamma;
 
        gamma = g_texture_globals.fGamma;
index 03b141ae67960b4f10ce4db9a90ffda6d00cb871..0f25c594ad56fe95ce58b0d03392799b47fbb84d 100644 (file)
@@ -43,6 +43,7 @@
 #include <vector>
 
 #include <uilib/uilib.h>
 #include <vector>
 
 #include <uilib/uilib.h>
+#include <util/buffer.h>
 
 #include "signal/signal.h"
 #include "math/vector.h"
 
 #include "signal/signal.h"
 #include "math/vector.h"
@@ -1567,7 +1568,7 @@ void TreeView_onRowActivated( GtkTreeView* treeview, GtkTreePath* path, GtkTreeV
        GtkTreeModel* model = gtk_tree_view_get_model( GTK_TREE_VIEW( treeview ) );
 
        if ( gtk_tree_model_get_iter( model, &iter, path ) ) {
        GtkTreeModel* model = gtk_tree_view_get_model( GTK_TREE_VIEW( treeview ) );
 
        if ( gtk_tree_model_get_iter( model, &iter, path ) ) {
-               gchar dirName[1024];
+               auto dirName = u::buffer<1024>();
 
                gchar* buffer;
                gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
 
                gchar* buffer;
                gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
@@ -1848,8 +1849,8 @@ void TextureBrowser_searchTags(){
        GSList* selected = NULL;
        GSList* node;
        gchar* tag;
        GSList* selected = NULL;
        GSList* node;
        gchar* tag;
-       char buffer[256];
-       char tags_searched[256];
+       auto buffer = u::buffer<256>();
+       auto tags_searched = u::buffer<256>();
 
        GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ) );
 
 
        GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ) );
 
@@ -2424,7 +2425,7 @@ void TextureBrowser_RefreshShaders(){
        GtkTreeIter iter;
        if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
        {
        GtkTreeIter iter;
        if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
        {
-               gchar dirName[1024];
+               auto dirName = u::buffer<1024>();
 
                gchar* buffer;
                gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
 
                gchar* buffer;
                gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
index a0a48c43f4460fcc35ea2d90b96e5e12b77e1b63..38b50538bfa6cbbeeb21a4a602487489284e5a6a 100644 (file)
@@ -24,8 +24,9 @@
 #if defined( DEBUG_CULLING )
 
 #include <stdio.h>
 #if defined( DEBUG_CULLING )
 
 #include <stdio.h>
+#include <util/buffer.h>
 
 
-char g_cull_stats[1024];
+u::BufferVal<1024> g_cull_stats;
 int g_count_dots;
 int g_count_planes;
 int g_count_oriented_planes;
 int g_count_dots;
 int g_count_planes;
 int g_count_oriented_planes;
index 4824d23e645021fa064d6950c227bfc65b42f0e1..6ac7f553666516c455a01660bd1ab828913b4498 100644 (file)
@@ -77,6 +77,7 @@ void message_print( message_info_t* self, const char* characters, std::size_t le
 
 #include <glib.h>
 #include <uilib/uilib.h>
 
 #include <glib.h>
 #include <uilib/uilib.h>
+#include <util/buffer.h>
 #include "xmlstuff.h"
 
 class CWatchBSP
 #include "xmlstuff.h"
 
 class CWatchBSP
@@ -400,7 +401,7 @@ static void saxComment( void *ctx, const xmlChar *msg ){
 }
 
 static void saxWarning( void *ctx, const char *msg, ... ){
 }
 
 static void saxWarning( void *ctx, const char *msg, ... ){
-       char saxMsgBuffer[4096];
+       auto saxMsgBuffer = u::buffer<4096>();
        va_list args;
 
        va_start( args, msg );
        va_list args;
 
        va_start( args, msg );
@@ -410,7 +411,7 @@ static void saxWarning( void *ctx, const char *msg, ... ){
 }
 
 static void saxError( void *ctx, const char *msg, ... ){
 }
 
 static void saxError( void *ctx, const char *msg, ... ){
-       char saxMsgBuffer[4096];
+       auto saxMsgBuffer = u::buffer<4096>();
        va_list args;
 
        va_start( args, msg );
        va_list args;
 
        va_start( args, msg );
@@ -420,7 +421,7 @@ static void saxError( void *ctx, const char *msg, ... ){
 }
 
 static void saxFatal( void *ctx, const char *msg, ... ){
 }
 
 static void saxFatal( void *ctx, const char *msg, ... ){
-       char buffer[4096];
+       auto buffer = u::buffer<4096>();
 
        va_list args;
 
 
        va_list args;
 
index 61a7a021cdc645b57a8e08ec45aef153de05e876..4e6b531e5aa1316257a27965c99ec1d9d426a924 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <uilib/uilib.h>
 #include <gdk/gdkkeysyms.h>
 
 #include <uilib/uilib.h>
 #include <gdk/gdkkeysyms.h>
+#include <util/buffer.h>
 
 #include "generic/callback.h"
 #include "string/string.h"
 
 #include "generic/callback.h"
 #include "string/string.h"
@@ -1437,7 +1438,7 @@ void XYWnd::XY_LoadBackgroundImage( const char *name ){
                globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
        }
 
                globalOutputStream() << "WARNING: could not extract the relative path, using full path instead\n";
        }
 
-       char fileNameWithoutExt[512];
+       auto fileNameWithoutExt = u::buffer<512>();
        strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
        fileNameWithoutExt[512 - 1] = '\0';
        fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
        strncpy( fileNameWithoutExt, relative, sizeof( fileNameWithoutExt ) - 1 );
        fileNameWithoutExt[512 - 1] = '\0';
        fileNameWithoutExt[strlen( fileNameWithoutExt ) - 4] = '\0';
@@ -1596,7 +1597,7 @@ void XYWnd::XY_DrawBackground( void ){
 void XYWnd::XY_DrawGrid( void ) {
        float x, y, xb, xe, yb, ye;
        float w, h, a;
 void XYWnd::XY_DrawGrid( void ) {
        float x, y, xb, xe, yb, ye;
        float w, h, a;
-       char text[32];
+       auto text = u::buffer<32>();
        float step, minor_step, stepx, stepy;
        step = minor_step = stepx = stepy = GetGridSize();
 
        float step, minor_step, stepx, stepy;
        step = minor_step = stepx = stepy = GetGridSize();
 
@@ -1778,7 +1779,7 @@ void XYWnd::XY_DrawBlockGrid(){
 
        float x, y, xb, xe, yb, ye;
        float w, h;
 
        float x, y, xb, xe, yb, ye;
        float w, h;
-       char text[32];
+       auto text = u::buffer<32>();
 
        glDisable( GL_TEXTURE_2D );
        glDisable( GL_TEXTURE_1D );
 
        glDisable( GL_TEXTURE_2D );
        glDisable( GL_TEXTURE_1D );