- asprintf( &p_sys->psz_file, "%s/%s %d-%d-%d %.2dh%.2dm%.2ds.%s",
- p_sys->psz_path, psz_name,
- l.tm_mday, l.tm_mon+1, l.tm_year+1900,
- l.tm_hour, l.tm_min, l.tm_sec,
- p_sys->psz_ext );
+ if( asprintf( &p_sys->psz_file, "%s %d-%d-%d %.2dh%.2dm%.2ds.%s",
+ ( psz_name != NULL ) ? psz_name : "Unknown",
+ l.tm_mday, l.tm_mon+1, l.tm_year+1900,
+ l.tm_hour, l.tm_min, l.tm_sec,
+ p_sys->psz_ext ) == -1 )
+ p_sys->psz_file = NULL;
+
+ free( psz_name );
+ if( p_sys->psz_file == NULL )
+ {
+ p_sys->b_dump = false;
+ return;
+ }
+
+ /* Remove all forbidden characters (except (back)slashes) */
+ for( psz = p_sys->psz_file; *psz; psz++ )
+ {
+ unsigned char c = (unsigned char)*psz;
+
+ /* Even if many OS accept non printable characters, we remove
+ * them to avoid confusing users */
+ if( ( c < 32 ) || ( c == 127 ) )
+ *psz = '_';
+#if defined (WIN32) || defined (UNDER_CE)
+ /* Windows has a lot of forbidden characters, even if it has
+ * fewer than DOS. */
+ if( strchr( "\"*:<>?|", c ) != NULL )
+ *psz = '_';
+#endif
+ }
+
+ psz_name = p_sys->psz_file;