Page 1 of 1

warning: 'sv' may be used uninitialized in this function

Posted: 2011-02-15T13:29:52-07:00
by yecril71pl
Magick.c: In function 'XS_Image__Magick_Transform':
Magick.xs:13522:8: warning: 'sv' may be used uninitialized in this function
Appears in many functions.

The first problem with these messages is lack of locality. At least within Transform, sv is a temporary variable used in an inner block, and it should be declared in block scope.

The second problem is that it is initialised by the macro AddImageToRegistry, which is as bad coding style as can be (macro name is CamelCase, the name sv is hardwired, side effects invisible and context-dependent). However, with the current implementation of perl.h it cannot be any better because it defines macros like tTHX that are types for some implementations and empty for other (non-concurrent probably), and if I offload AddImageToRegistry to a static function I gain readability but I lose the warning (ironically) although the semantics did not change.

Cure:

Code: Select all

    do 
    {
      assert (image);
      clone=CloneImage(image,0,0,MagickTrue,exception);
      if ((clone == (Image *) NULL) || (exception->severity >= ErrorException))
        goto PerlException;
      TransformImage(&clone,crop_geometry,geometry);
      do 
      {
      register SV *sv; 
        assert (clone);
        assert (magick_registry);
        AddImageToRegistry(clone);
        rv=newRV(sv);
        av_push(av,sv_bless(rv,hv));
        SvREFCNT_dec(sv);
      } while (0 + (clone = clone -> next));
    } while (0 + (image = image -> next));
I have a patch for PerlMagick.xs. This is a cumulative patch that covers other problems as well.