This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] enhancement of mi_cmd_data_write_memory_bytes for filling memory regions (was [PATCH] new MI command for pattern filling of memory regions)


> From: Giuseppe MONTALTO <giuseppe.montalto@st.com>
> Cc: "palves@redhat.com" <palves@redhat.com>,
> 	"tromey@redhat.com" <tromey@redhat.com>,
> 	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
> 	"Hafiz_Abid@mentor.com" <Hafiz_Abid@mentor.com>
> Date: Fri, 19 Oct 2012 16:11:50 +0200
> 
> Incidentally, the attached patch contains the sscanf() version of the loop mentioned here below:
> 
>   for (i = 0; i < len; ++i)
>     {
>       int x;
>       if (sscanf (cdata + i * 2, "%02x", &x) != 1)
>         error (_("Invalid argument"));
>       databuf[i] = (gdb_byte) x;
>     }
> 
> While, on the other hand, using strtoul() instead of sscanf() will lead to something 
> like this, or so I guess:
> 
>   for (i = 0; i < len; ++i)
>       databuf[i] = strtoul (cdata + i * 2, NULL, 16);
> 
> The former still being my preferred one, I think it all comes down to personal taste, doesn't it?

Not necessarily.  If you pass a non-NULL 2nd argument to strtoul, you
can check for errors with better accuracy.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]