View Issue Details

IDProjectCategoryView StatusLast Update
0018310FPC-public2010-12-24 13:44
Reportergreensoft Assigned ToSergei Gorelkin  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
Summary0018310: uses zlib compress Compiler normal but Run Error (SIGSEGV)
DescriptionLAZARUS Code

uses Zlib

procedure TForm1.Button7Click(Sender: TObject);
var
  Spc,Xpl:pbytef;
  Ax: array [0..51] of char ;
  spl:uLong;
  Dpl:puLongf ;
  CI:longint;

begin
  Ax:='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  Spc:=@Ax;

  spl:=52;
  Dpl:=puLongf(compressBound(spl));
  Ci:=compress(Xpl,Dpl,Spc,spl); //
{ Case Ci of
    Z_OK : LabeledEdit3.Text := 'success;
    Z_MEM_ERROR : LabeledEdit3.Text := 'not enough memory;
    Z_BUF_ERROR : LabeledEdit3.Text := 'not enough room ;
    else LabeledEdit3.Text := 'failure';
  end; }

end;
Additional Informationmy E-Mail : greensoft@139.com
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Vincent Snijders

2010-12-24 09:07

manager   ~0044551

Last edited: 2010-12-24 09:08

Please, create a compilable console application that show the error.

Explain, why it is a FPC/Lazarus/Zlib error and not a error in the program.

Marco van de Voort

2010-12-24 09:37

manager   ~0044552

You filled in Windows, yet you use zlib (and not paszlib). This means that probably some zlib.dll is used, and besides the testprogram mentioned by Vincent we'll also need to now which DLL you used.

greensoft

2010-12-24 12:05

reporter   ~0044559

zlib1.Dll VERSION (1.2.2 , 1.2.4 ,1.2.5) all be Used

Sergei Gorelkin

2010-12-24 13:43

developer   ~0044564

The 'compress' function expects caller to supply a valid destination buffer. In this example, the destination buffer isn't allocated and points to garbage.
Moreover, destination length is passed by value, while you should pass a pointer to variable.
The correct code should look something like that:

var Dpl: ulongf;

Dpl:=CompressBound(spl);
GetMem(Xpl,Dpl);
compress(Xpl, @Dpl, Spc, Spl);
// Dpl is now actual length of compressed data
...

// after compressed data is no longer needed:
FreeMem(Dpl);

Issue History

Date Modified Username Field Change
2010-12-24 05:26 greensoft New Issue
2010-12-24 05:26 greensoft Widgetset => Win32/Win64
2010-12-24 09:07 Vincent Snijders LazTarget => -
2010-12-24 09:07 Vincent Snijders Note Added: 0044551
2010-12-24 09:07 Vincent Snijders Status new => feedback
2010-12-24 09:08 Vincent Snijders Note Edited: 0044551
2010-12-24 09:08 Vincent Snijders Project Lazarus => FPC
2010-12-24 09:37 Marco van de Voort Note Added: 0044552
2010-12-24 12:05 greensoft Note Added: 0044559
2010-12-24 13:43 Sergei Gorelkin Note Added: 0044564
2010-12-24 13:44 Sergei Gorelkin Status feedback => resolved
2010-12-24 13:44 Sergei Gorelkin Resolution open => no change required
2010-12-24 13:44 Sergei Gorelkin Assigned To => Sergei Gorelkin