Web lists-archives.com

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




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;

_______________________________________________
MPlayer-dev-eng mailing list
MPlayer-dev-eng@xxxxxxxxxxxx
https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng