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

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
yecril71pl
Posts: 81
Joined: 2011-02-08T11:06:09-07:00
Authentication code: 8675308
Location: Warsaw, Poland
Contact:

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

Post 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.
Post Reply