[CinCV TNG] [PATCH] Quicker initialization of empty strings (s[0]=0; instead of sprintf(s,""); )

Petter Reinholdtsen pere at hungry.com
Fri May 2 14:22:32 CEST 2014


Hi.  Her is a new patch cleaing up some warnings exposed by -Wformat.
It seem a complete waste to use sprintf() to store a zery byte at the
start of a char array, so I propose to use use 'str[0] = 0;' or
'char str[size] = {0};' instead.

I've only looked at the guicast and cinelerra directories.

The change is also available in the branch
<URL: https://github.com/petterreinholdtsen/cinelerra-cv/tree/fix-format-zero-length >.

commit 0738db18b191b1d17147df4bec98f3383930726e
Author: Petter Reinholdtsen <pere at hungry.com>
Date:   Fri May 2 14:15:26 2014 +0200

    Use s[0]=0 instead of sprintf(s,) to null terminate an empty
    string.  Get rid of warning: zero-length gnu_printf format string
    [-Wformat-zero-length].

diff --git a/cinelerra/audioesound.C b/cinelerra/audioesound.C
index 7ef6a28..95e5ce3 100644
--- a/cinelerra/audioesound.C
+++ b/cinelerra/audioesound.C
@@ -84,7 +84,7 @@ char* AudioESound::translate_device_string(char *server, int port)
 	if(port > 0 && strlen(server))
 		sprintf(device_string, "%s:%d", server, port);
 	else
-		sprintf(device_string, "");
+		device_string[0] = 0;
 	return device_string;
 }
 
diff --git a/cinelerra/menueffects.C b/cinelerra/menueffects.C
index 6f14db2..7670256 100644
--- a/cinelerra/menueffects.C
+++ b/cinelerra/menueffects.C
@@ -92,7 +92,7 @@ MenuEffectPacket::~MenuEffectPacket()
 MenuEffectThread::MenuEffectThread(MWindow *mwindow)
 {
 	this->mwindow = mwindow;
-	sprintf(title, "");
+	title[0] = 0;
 }
 
 MenuEffectThread::~MenuEffectThread()
diff --git a/cinelerra/playbackconfig.C b/cinelerra/playbackconfig.C
index d110502..434588f 100644
--- a/cinelerra/playbackconfig.C
+++ b/cinelerra/playbackconfig.C
@@ -45,7 +45,7 @@ AudioOutConfig::AudioOutConfig(int duplex)
 		sprintf(oss_out_device[i], "/dev/dsp");
 	}
 
-	sprintf(esound_out_server, "");
+	esound_out_server[0] = 0;
 	esound_out_port = 0;
 
 	sprintf(alsa_out_device, "default");
@@ -264,7 +264,7 @@ VideoOutConfig::VideoOutConfig()
 	driver = PLAYBACK_X11_XV;
 	buz_out_channel = 0;
 	buz_swap_fields = 0;
-	sprintf(x11_host, "");
+	x11_host[0] = 0;
 	x11_use_fields = USE_NO_FIELDS;
 
 	firewire_channel = 63;
diff --git a/cinelerra/recordconfig.C b/cinelerra/recordconfig.C
index 49d1cd3..6e076ea 100644
--- a/cinelerra/recordconfig.C
+++ b/cinelerra/recordconfig.C
@@ -46,7 +46,7 @@ AudioInConfig::AudioInConfig()
 	firewire_port = 0;
 	firewire_channel = 63;
 	strcpy(firewire_path, "/dev/dv1394");
-	sprintf(esound_in_server, "");
+	esound_in_server[0] = 0;
 	esound_in_port = 0;
 
 	sprintf(alsa_in_device, "default");
@@ -184,7 +184,7 @@ VideoInConfig::VideoInConfig()
 	sprintf(v4l2jpeg_in_device, "/dev/video0");
 	sprintf(lml_in_device, "/dev/mvideo/stream");
 	sprintf(buz_in_device, "/dev/video0");
-	sprintf(screencapture_display, "");
+	screencapture_display[0] = 0;
 
 
 // DVB
diff --git a/cinelerra/tracks.C b/cinelerra/tracks.C
index 47828d9..1401b3d 100644
--- a/cinelerra/tracks.C
+++ b/cinelerra/tracks.C
@@ -189,9 +189,8 @@ printf("Tracks::operator= 1\n");
 int Tracks::load(FileXML *xml, int &track_offset, uint32_t load_flags)
 {
 // add the appropriate type of track
-	char string[BCTEXTLEN];
+	char string[BCTEXTLEN] = {0};
 	Track *track = 0;
-	sprintf(string, "");
 	
 	xml->tag.get_property("TYPE", string);
 
diff --git a/cinelerra/tracksedit.C b/cinelerra/tracksedit.C
index 6d14dd8..ecae000 100644
--- a/cinelerra/tracksedit.C
+++ b/cinelerra/tracksedit.C
@@ -681,8 +681,7 @@ void Tracks::paste_automation(double selectionstart,
 	double length;
 	double frame_rate = edl->session->frame_rate;
 	int64_t sample_rate = edl->session->sample_rate;
-	char string[BCTEXTLEN];
-	sprintf(string, "");
+	char string[BCTEXTLEN] = {0};
 
 // Search for start
 	do{
diff --git a/cinelerra/vdeviceprefs.C b/cinelerra/vdeviceprefs.C
index 11ffbbf..250b1eb 100644
--- a/cinelerra/vdeviceprefs.C
+++ b/cinelerra/vdeviceprefs.C
@@ -519,7 +519,7 @@ char* VDriverMenu::driver_to_string(int driver)
 			break;
 #endif
 		default:
-			sprintf(string, "");
+			string[0] = 0;
 	}
 	return string;
 }
diff --git a/guicast/bcfilebox.C b/guicast/bcfilebox.C
index 28d5e1d..1f785a3 100644
--- a/guicast/bcfilebox.C
+++ b/guicast/bcfilebox.C
@@ -503,7 +503,7 @@ BC_FileBox::BC_FileBox(int x,
 		fs->complete_path(this->current_path);
 		fs->update(this->current_path);
 		strcpy(directory, fs->get_current_dir());
-		sprintf(filename, "");
+		filename[0] = 0;
 	}
 
 
diff --git a/guicast/bcrecentlist.C b/guicast/bcrecentlist.C
index a6f8e83..6d29e97 100644
--- a/guicast/bcrecentlist.C
+++ b/guicast/bcrecentlist.C
@@ -88,9 +88,8 @@ int BC_RecentList::load_items(const char *prefix) {
 	int count;
 	for (count = 0; count < RECENT_MAX_ITEMS; count++) {
 		char save[BCTEXTLEN];
-		char text[BCTEXTLEN];
+		char text[BCTEXTLEN] = {0};
 		sprintf(save, "RECENT_%s_%s_%d", prefix, type, count);
-		sprintf(text, "");
 		defaults->get(save, text);
 		if (strlen(text) == 0) break;
 		items.append(new BC_ListBoxItem(text));
diff --git a/guicast/filesystem.C b/guicast/filesystem.C
index 712317f..23fbcfd 100644
--- a/guicast/filesystem.C
+++ b/guicast/filesystem.C
@@ -700,7 +700,7 @@ int FileSystem::extract_name(char *out, const char *in, int test_dir)
 	int i;
 
 	if(test_dir && is_dir(in))
-		sprintf(out, "");    // complete string is directory
+		string[0] = 0;    // complete string is directory
 	else
 	{
 		for(i = strlen(in)-1; i > 0 && in[i] != '/'; i--)


More information about the Cinelerra mailing list