[FFmpeg-devel] [PATCH] Fix a segmentfault in libavutil/opencl.c

Y.C. Liu liuycsd at gmail.com
Tue Apr 22 16:24:22 CEST 2014


2014-04-20 12:16 GMT+08:00, Michael Niedermayer <michaelni at gmx.at>:
> On Sun, Apr 13, 2014 at 09:57:04PM +0800, Y.C. Liu wrote:
>>
>
>>  opencl.c |    5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>> 7199763f13633220bdc21b9c1dc8794e40719729  patch_libavutil_opencl_c.diff
>> diff -Naur a/libavutil/opencl.c b/libavutil/opencl.c
>> --- a/libavutil/opencl.c	2014-04-13 20:57:31.619635645 +0800
>> +++ b/libavutil/opencl.c	2014-04-13 21:53:59.999519428 +0800
>> @@ -168,8 +168,9 @@
>>
>>  const char *av_opencl_errstr(cl_int status)
>>  {
>> -    int i;
>> -    for (i = 0; i < sizeof(opencl_err_msg); i++) {
>> +    int i,l;
>> +    l = sizeof(opencl_err_msg)/sizeof(OpenclErrorMsg);
>> +    for (i = 0; i < l; i++) {
>
> this should be using FF_ARRAY_ELEMS()
>
> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Its not that you shouldnt use gotos but rather that you should write
> readable code and code with gotos often but not always is less readable
>

New patch attached.
Using FF_ARRAY_ELEMS().
Thanks.
-------------- next part --------------
diff -Naur a/libavutil/opencl.c b/libavutil/opencl.c
--- a/libavutil/opencl.c	2014-04-22 22:05:59.214401428 +0800
+++ b/libavutil/opencl.c	2014-04-22 22:18:21.498432043 +0800
@@ -169,7 +169,7 @@
 const char *av_opencl_errstr(cl_int status)
 {
     int i;
-    for (i = 0; i < sizeof(opencl_err_msg); i++) {
+    for (i = 0; i < FF_ARRAY_ELEMS(opencl_err_msg); i++) {
         if (opencl_err_msg[i].err_code == status)
             return opencl_err_msg[i].err_str;
     }


More information about the ffmpeg-devel mailing list