[MPlayer-dev-eng] [PATCH] input.c: optimize mp_cmd list.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sun Feb 14 13:00:57 CET 2016


On Sun, Feb 14, 2016 at 12:19:21AM +0100, Ingo Brückl wrote:
> Reimar Döffinger wrote on Sat, 13 Feb 2016 23:44:42 +0100:
> 
> > the normal avstrlcpy etc. would just silently truncate.
> 
> Isn't code not working preferable to code presumably crashing?

Not working is not working.
The only things making a difference there is security
concerns and ease of debugging/fixing.
Crashing loses in case the former exists, but it clearly
wins in the second one.
So actually, I generally consider a safe crash a good thing.
That said, I was rather thinking of something like below,
if that looks good to you (it could also check for NULL termination
or alternatively use memcpy, I haven't thought that through):
--- a/input/input.h
+++ b/input/input.h
@@ -201,6 +201,11 @@ typedef enum {
 #define MP_MAX_KEY_DOWN 8
 #endif
 
+#define ARRAY_STRCPY(d, s) do { \
+    typedef char dst_size_check[(sizeof(d) >= sizeof(s))*2-1]; \
+    strcpy(&(d), &(s)); \
+} while(0)
+
 typedef union mp_cmd_arg_value {
   int i;
   float f;



More information about the MPlayer-dev-eng mailing list