This is under Debian Bullseye Linux on a PineBook Pro so ARM 64-bit I
think although sizeof(int) is still 4.   It's a fairly complicated
program at 750 lines in it's almost-done state so I'm not posting the
whole thing.  I have this program that does audiograms
https://sourceforge.net/projects/audiogram-c/ and I got the bright
idea of adding FFT plots to the video generated.  I read a wav file
into RAM, draw the envelope of the audio.  Then move a cursor bar over
it by generating frames at different times, saving as jpegs and
calling ffmpeg at the end to make a video.  Originally it was a
work-around for not being able to post audio files to social media
sites.

The FFT version works with the PCM data in the wav file in memory and
draws more onto the same frames.  tmpbuf is a per-frame output drawing
area allocated with calloc and then cleared with bzero but I still get
these uninitialized warnings:

==26220==
==26220== Invalid write of size 1
==26220==    at 0x402460: plot (agf.c:573)
==26220==    by 0x402B9F: main (agf.c:713)
==26220==  Address 0x4d2b993 is 13 bytes before an unallocated block
of size 3,278,400 in arena "client"
==26220==
==26220== Conditional jump or move depends on uninitialised value(s)
==26220==    at 0x401504: plotffts (agf.c:301)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Conditional jump or move depends on uninitialised value(s)
==26220==    at 0x40153C: plotffts (agf.c:303)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Conditional jump or move depends on uninitialised value(s)
==26220==    at 0x401598: plotffts (agf.c:307)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Conditional jump or move depends on uninitialised value(s)
==26220==    at 0x4015D0: plotffts (agf.c:309)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Conditional jump or move depends on uninitialised value(s)
==26220==    at 0x40165C: plotffts (agf.c:315)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Conditional jump or move depends on uninitialised value(s)
==26220==    at 0x401678: plotffts (agf.c:317)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Use of uninitialised value of size 8
==26220==    at 0x4016E0: plotffts (agf.c:328)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Use of uninitialised value of size 8
==26220==    at 0x4016F8: plotffts (agf.c:329)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Use of uninitialised value of size 8
==26220==    at 0x401710: plotffts (agf.c:330)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Conditional jump or move depends on uninitialised value(s)
==26220==    at 0x401788: plotffts (agf.c:337)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Conditional jump or move depends on uninitialised value(s)
==26220==    at 0x4017A4: plotffts (agf.c:339)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Use of uninitialised value of size 8
==26220==    at 0x4017EC: plotffts (agf.c:342)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Invalid write of size 1
==26220==    at 0x4017EC: plotffts (agf.c:342)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Address 0x4dbb9dc is 4 bytes before an unallocated block of
size 2,688,512 in arena "client"
==26220==
==26220== Use of uninitialised value of size 8
==26220==    at 0x401804: plotffts (agf.c:343)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Invalid write of size 1
==26220==    at 0x401804: plotffts (agf.c:343)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Address 0x4dbb9dd is 3 bytes before an unallocated block of
size 2,688,512 in arena "client"
==26220==
==26220== Use of uninitialised value of size 8
==26220==    at 0x40181C: plotffts (agf.c:344)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Uninitialised value was created by a heap allocation
==26220==    at 0x4849E4C: malloc (vg_replace_malloc.c:307)
==26220==    by 0x40125B: fft_init (agf.c:173)
==26220==    by 0x402B63: main (agf.c:707)
==26220==
==26220== Invalid write of size 1
==26220==    at 0x40181C: plotffts (agf.c:344)
==26220==    by 0x401DDF: makeframes (agf.c:442)
==26220==    by 0x402BA3: main (agf.c:714)
==26220==  Address 0x4dbb9de is 2 bytes before an unallocated block of
size 2,688,512 in arena "client"
==26220==

The invalid writes I can't figure out either.  The code section looks like this:

void plotffts(void) { // draw to tmpbuf
  int i = 0; // initialize everything for Valgrind
  int ofs = 0;
  float min = -99999.9;  // floats work better
  float max = 99999.9;
  int x = EDGESKIP; // start at left side
  int y = 0;
  int oldx = EDGESKIP;
  int oldy = 0;
  int first = 1;
  half = HEIGHT/2; // redundant
  for (i=EDGESKIP; i<(FFTSIZE-EDGESKIP); i++) { // common values for both L&R
    if (fft_r[i] < min)  // unitialized value
      min = fft_r[i];
    if (fft_r[i] > max) // something not initialized
      max = fft_r[i];
  }
  for (i=EDGESKIP; i<(FFTSIZE-EDGESKIP); i++) { // read other channel
    if (fft_l[i] > max) // uninit
      max = fft_l[i];
    if (fft_l[i] < min) // uninit
      min = fft_l[i];
  }
  for (i=EDGESKIP; i<(FFTSIZE-EDGESKIP); i++) {  // right channel
    x = i;  // correct?
    y = ((fft_r[i] - min) / max) * half;
    if (y > half) // uninit
      y = half;
    if (y < 0) // uninit
      y = 0;
    if (first > 0) {
      oldy = y;
      first = 0;
    }
//    line(oldx,oldy,x,y);
    oldx = x;
    oldy = y;
///*
    ofs = (y * WIDTH * 3) + (x * 3);
    tmpbuf[ofs] = 0x01;  // Use of uninitialised value of size 8
    tmpbuf[ofs+1] = 0xf5; // Use of uninitialised value of size 8
    tmpbuf[ofs+2] = 0xf6; // Use of uninitialised value of size 8
//*/
  }
  oldx = EDGESKIP;
  for (i=EDGESKIP; i<(FFTSIZE-EDGESKIP); i++) {  // left channel
    x = i;
    y = ((fft_l[i] - min) / max) * half;
    if (y > half)  // uninit
      y = half;
    if (y < 0) // uninit
      y = 0;
    ofs = ((y + half)* WIDTH * 3) + (x * 3);
    tmpbuf[ofs] = 0x01; // uninitialised value of size 8 & Invalid
write of size 1
    tmpbuf[ofs+1] = 0xf5;  // uninitialised value of size 8 & Invalid
write of size 1
    tmpbuf[ofs+2] = 0xf6; // uninitialised value of size 8 & Invalid
write of size 1
  }
  // lines instead of dots would work better
}

I've looked up the line numbers given in the Valgrind error messages
and put comments on those lines above.  tmpbuf is where I'm doing
graphics, it's a chunk of RAM from calloc with an int8_t  pointer
making it accessible.  It's not live graphics but a buffer of 24-bit
color values which get written out to jpegs.  Maybe I should use
32-bit color?  This code does work, but I'm adding to it (Bresenham
line drawing) and the error messages are distracting me from errors in
the new code I'm working on.  My hunch is that something is still
incomplete in Valgrind on aarch64 platforms.

  Alan
-- 
-------------
Education is contagious.


_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to