Re: memcmp() checker: memory access errors




Kohn Emil Dan wrote:
On Mon, 18 Dec 2006, kolmogolov@xxxxxxxxx wrote:

<snipped>

BTW. I do ungetc() all 256 bytes in data[] back to the stream
for decoupling the probe_img() from all the other functions
for parsing the details of the headers. I thought tha it were s
a proper size for probing many kinds of my image files.



Be careful, because ungetc() can fail to push back the bytes to the input
stream. The standard guarantees that only one push back can succeed
without an intervening read or file positioning function (in which case
your pushed back characters will be be discarded).

So, for safety I'll have to either maintain a 256-byte global buffer
or to minimize the size of it whenever possible if I insist on not
calling
fseek() for the sake of being able to read from a pipe (which is off
topic).

I have also installed the memory debugger valgrin mentioned by malc.
Thanks too. This is really handy for checking at runtime and it did
report
my 256-byte memory leak although it did not report any other error.
So, I'll be serious about the free() which is left out also in the
actual
function. And I see that this is no good practice at all. The same to
assert() and NDEBUG. I have reread the manpage, removed all asserts,
and have gotten the same result from the Checker. It reported 4 memory
access errors supposedly at memcmp as Richard has noted. But the
Checker does not report the source-line every time. I have not
strip'ped
the symbols from the binary though.

Even after I changed

if ( 1 != fread(data, probe_len, 1, fp) ) return -2;

explicitly to

n_items_read = fread(data, probe_len, 1, fp);
if ( 1 != n_items_read ) return -2;

I got the same result of reading 4 uninitialized bytes in the stack
at the line

if ( !memcmp(data, KDF_header, 4) )

I thought this could have been the data[0] to data[3] because
KDF_header[] has been unconditonally declared and initialized.

What next? Do you think I should send in a bug-report to the author
of my Checker?

.



Relevant Pages

  • XLANGPart.LoadFrom(stream) failing - UnauthorizedAccessException
    ... My component then generates a PDF stream using Crystal Reports, ... attempts to load the XLANGMessage's 1st data part with the stream generated ... ReportDocument report = new ReportDocument; ... Exception thrown from: segment 1, ...
    (microsoft.public.biztalk.general)
  • How to print only certain page(s) in Microsoft Reports rdlc
    ... to load it to report viewer first. ... printDoc.PrinterSettings.PrinterName = printerName; ... Stream stream = new MemoryStream; ... private void Export ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Macrovision
    ... How is my video capture driver supposed to report that the incoming signal ... in the dwFrameFlags in the stream header of every VBI packet I send. ... I also tried setting those flags in the dwFrameFlags of every video frame, ... If anyone has succeeded in reporting Macrovisionness and had it be ...
    (microsoft.public.win32.programmer.directx.video)
  • RE: Asynchronous Web Service Method Failure
    ... service methods through a proxy if the method opens a stream reader or stream ... If I call the CreateReport method using the proxy, ... > to invoke on what side of a web service method call) is eluding me. ... >>particular report. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: SQL server 2000 RS printing problem
    ... SnapshotCompression to 'SQL' as specified in Server system properties. ... ReportingServices.Diagnostics.Utilities.StreamNotFoundException: The stream ... that is provided to an operation cannot be located in the report server ... reports from the reporting service website on the client server. ...
    (microsoft.public.sqlserver.tools)