Recent

Author Topic: Project1 raised exception class: External : SIGSEGV at addres 403920  (Read 4363 times)

Raf20076

  • Full Member
  • ***
  • Posts: 153
    • https://github.com/Raf20076
Hi guys

I have a small problem. I have just written  spellchecker code example and I have put in wiki website as https://wiki.freepascal.org/spelling#Demo_3_-_Spellchecker_-_non_characters.2C_carriage_return.2C_split_string. The code works very well but sometimes gives errors especially two.
For this code I use hunspell.dll 1.3.2 compiled with Visual C++ 2010 (not mine) 32 bit (I'm using Windows 7 32bit)

It seems to me when spellchecker is calling some dll functions in libhunspell.dll it causes Access Violation.
You can read it in here https://stackoverflow.com/questions/52081289/compiling-hunspell-as-static-library-in-c-builder

Quote
I used Visual Studio 2015 Community to build the DLL - libhunspell.dll. To avoid dependencies, I used the /MT option in the compiler. I had many problems using the version of the DLL which was dependent on VC++ 2015 Redistributable ("Access Violation" errors immediately after calling some DLL functions), so statically linking the Redistributable to remove the dependency, all of these problems magically disappeared. Even though the compiler reported some warnings which is probably another question, it did manage to build the DLL.


So when I test it it in Lazarus Ide - sometimes gives me two errors: in Asembler window

exception class: External : SIGSEGV at addres 403920
exception class: External : SIGSEGV at addres 408B44 cmpl $0x0, -0x8(%eax) which points at SYSTEM$$_NEWANSISTRING$$LONGINT$$POINTER(79)

Is there any way to sort it out within the code? Or rather find another hunspell.dll or maybe compile it (I'd prefer rather not), https://delphihaven.wordpress.com/2010/02/06/compiling-a-hunspell-dll-step-by-step/

What is your advice?

Thanks

jamie

  • Hero Member
  • *****
  • Posts: 5197
You need to show how you are accessing the DLL functions..

 It looks to me that you are passing it strings with no Null termination and no pre-allocated
space.

 The calling convention comes into play too.. but I am betting that you are giving it strings with no regard for nulls and space allocation.

Sorry, I over looked the post you gave, I'll look at it.
« Last Edit: July 28, 2019, 04:59:35 pm by jamie »
The only true wisdom is knowing you know nothing

Raf20076

  • Full Member
  • ***
  • Posts: 153
    • https://github.com/Raf20076
The example of the code is in here https://wiki.freepascal.org/spelling#Demo_3_-_Spellchecker_-_non_characters.2C_carriage_return.2C_split_string

Text from Memo1 is split into words and allocated in Array, see the above example.

Thanks

jamie

  • Hero Member
  • *****
  • Posts: 5197
The "Suggest" method looks suspicious.
 
 You are incrementing the pointer address by the size of the pointer for one thing..

 you don't need to do that.

 Words^[ I ]..

 I really don't see how that is working at that junction.

 I guess I could load it, where is the DLL file ?
The only true wisdom is knowing you know nothing

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Make sure that you call UniqueString (https://www.freepascal.org/docs-html/rtl/system/uniquestring.html) when passing String types to to external libraries.

Raf20076

  • Full Member
  • ***
  • Posts: 153
    • https://github.com/Raf20076
Quote
The "Suggest" method looks suspicious.
Why? The Hunspell Interface is not mine I have just applied to it

Quote
You are incrementing the pointer address by the size of the pointer for one thing..
How can I fix it?

You mean in Hunspell Interface

Code: Pascal  [Select][+][-]
  1. List.clear;
  2.     try
  3.         len := hunspell_suggest(Speller, SugList, PChar(Word));
  4.         Words := SugList;
  5.         for i := 1 to len do begin
  6.             List.Add(Words^);
  7.             Inc(PtrInt(Words), sizeOf(Pointer));

Quote
I guess I could load it, where is the DLL file ?
It's from the Internet, but I use someone post it in this forum, don't remember who.



« Last Edit: July 28, 2019, 05:40:38 pm by Raf20076 »

jamie

  • Hero Member
  • *****
  • Posts: 5197
Most likely this site

https://forum.lazarus.freepascal.org/index.php/topic,39930.0.html

After reading that I think I'll stay away... I would rather create a DLL from the original files using FPC/Lazarus than using one with all the mess.

if you want, you could try to modify that code...

 List.Text := Words^;

Since I see in code above its one long line with CR/LF so it should go in.
« Last Edit: July 28, 2019, 06:26:16 pm by jamie »
The only true wisdom is knowing you know nothing

Raf20076

  • Full Member
  • ***
  • Posts: 153
    • https://github.com/Raf20076
I have hint that Conversion between ordinals and pointers is not portable
It points to code in Hunspell Interface

Inc(PtrInt(Words), size Of(Pointer));

jamie

  • Hero Member
  • *****
  • Posts: 5197
try this.

Code: Pascal  [Select][+][-]
  1. procedure THunspell.Suggest(Word: string; List: TStrings);
  2. var i, len: Integer;
  3.         SugList, Words: PPChar;
  4. begin
  5.     List.clear;
  6.     If Word = '' Then exit else Word := Word+#0; // Add a null to it to make sure
  7.     try
  8.         len := hunspell_suggest(Speller, SugList, PChar(Word));
  9.         Words := SugList;
  10.         for i := 1 to len do begin
  11.             List.Add(Words^);
  12.             Inc(PtrInt(Words), sizeOf(Pointer));
  13.         end;
  14.     finally
  15.         Hunspell_free_list(Speller, SugList, len);
  16.     end;
  17. end;
  18.  
Code: Pascal  [Select][+][-]
  1. procedure THunspell.Suggest(Word: string; List: TStrings);
  2. var i, len: Integer;
  3.         SugList, Words: PPChar;
  4. begin
  5.     List.clear;
  6.     If Word = '' Then exit else Word := Word+#0; // Add a null to it to make sure
  7.     try
  8.         len := hunspell_suggest(Speller, SugList, PChar(Word));
  9.         Words := SugList;
  10.         List.Text := Words^;
  11.     finally
  12.         Hunspell_free_list(Speller, SugList, len);
  13.     end;
  14. end;
  15.  
  16.  

And try that one...

« Last Edit: July 28, 2019, 07:32:33 pm by jamie »
The only true wisdom is knowing you know nothing

Raf20076

  • Full Member
  • ***
  • Posts: 153
    • https://github.com/Raf20076
I have error
Incompatible types got Char expected LongIng.  Points at  #0 in Word := + #0

jamie

  • Hero Member
  • *****
  • Posts: 5197
first off, please rename all the "word" to "aWord"
Word is a reserved type.
The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8754
  • Debugger - SynEdit - and more
    • wiki
So when I test it it in Lazarus Ide - sometimes gives me two errors: in Asembler window

exception class: External : SIGSEGV at addres 403920
exception class: External : SIGSEGV at addres 408B44 cmpl $0x0, -0x8(%eax) which points at SYSTEM$$_NEWANSISTRING$$LONGINT$$POINTER(79)

Have you opened the stacktrace window? what does it show?

Exception in NewAnsiString is rare. It most likely either means you do pointer type casts with string variable; or use move/fillchar/... on strings. Or your app somewere writes to a dangling pointer (i.e. to random mem) and just happens to hit that string by chance.

BrunoK

  • Sr. Member
  • ****
  • Posts: 381
  • Retired programmer
So when I test it it in Lazarus Ide - sometimes gives me two errors: in Asembler window

exception class: External : SIGSEGV at addres 403920
exception class: External : SIGSEGV at addres 408B44 cmpl $0x0, -0x8(%eax) which points at SYSTEM$$_NEWANSISTRING$$LONGINT$$POINTER(79)

Do you use cmem ?

If yes, someone mentionned something in the bugtracker. I added my own remark on that. Search key word "cmem".

PascalDragon

  • Hero Member
  • *****
  • Posts: 4970
  • Compiler Developer
try this.

Code: Pascal  [Select][+][-]
  1. procedure THunspell.Suggest(Word: string; List: TStrings);
  2. var i, len: Integer;
  3.         SugList, Words: PPChar;
  4. begin
  5.     List.clear;
  6.     If Word = '' Then exit else Word := Word+#0; // Add a null to it to make sure
  7.     try
  8.         len := hunspell_suggest(Speller, SugList, PChar(Word));
  9.         Words := SugList;
  10.         for i := 1 to len do begin
  11.             List.Add(Words^);
  12.             Inc(PtrInt(Words), sizeOf(Pointer));
  13.         end;
  14.     finally
  15.         Hunspell_free_list(Speller, SugList, len);
  16.     end;
  17. end;
  18.  
It's not necessary to add a NUL character, because Pascal strings are implicitly always NUL-terminated. The original Suggest method doesn't look suspicious either (though the Inc(PtrInt(Words), SizeOf(Pointer)); could be simplified to Inc(Words);).

jamie

  • Hero Member
  • *****
  • Posts: 5197
In this case I don't think even an increment is needed because the declaration is "PPChar", a pointer to a pointer;
 wouldn't this work as well without the increments?

Code: Pascal  [Select][+][-]
  1.  For i := 0 to len-1 do
  2.    List.Add(Words[i]^);
  3.  

 I also notice he maybe indexing one to few doing the 1 to len-1 instead of 1 to len

 Just thinking out loud here.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018