View Issue Details

IDProjectCategoryView StatusLast Update
0017871FPCDatabasepublic2016-02-05 13:40
ReporterSven Barth Assigned ToLacaK  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
PlatformARMOSWinCE 
Product Version2.5.1 
Fixed in Version3.0.0 
Summary0017871: [WinCE] Bus error when using TSdfDataset
DescriptionI tried to use TSdfDataset in a Windows Mobile ARM application, but I got an EBusError exception when I tried to do anything useful with the Dataset (the first occurence was when calling "First").
Additional InformationThe attached patch adds some "unaligned(...)" typecasts to sdfdata.pp. As I don't know whether all of these are necessary or whether they are done the right way (it works now, though ^^), I'd like someone more experienced with unaligned to comment on this.

I'll also attach a modified version of testsdf.pp which shows the bus error exception as well (but here the first critical call is not "First"). The modifications are mostly related to the fact that WinCE doesn't have a console (by default) nor a current directory.
TagsNo tags attached.
Fixed in Revision30883
FPCOldBugId
FPCTarget
Attached Files

Relationships

related to 0022177 closedLudo Brands Bus error or misaligned data access. 

Activities

2010-11-07 20:25

 

sdfdata-unaligned.patch (2,258 bytes)   
Index: packages/fcl-db/src/sdf/sdfdata.pp
===================================================================
--- packages/fcl-db/src/sdf/sdfdata.pp	(Revision 16312)
+++ packages/fcl-db/src/sdf/sdfdata.pp	(Arbeitskopie)
@@ -474,7 +474,7 @@
   begin
     if (CalcFieldsSize > 0) then
       GetCalcFields(Buffer);
-    with PRecInfo(Buffer + FRecInfoOfs)^ do
+    with unaligned(PRecInfo(Buffer + FRecInfoOfs)^) do
     begin
       BookmarkFlag := bfCurrent;
       RecordNumber := PtrInt(FData.Objects[FCurRec]);
@@ -496,7 +496,7 @@
 begin
   Result := -1;
   if GetActiveRecBuf(BufPtr) then
-    Result := PRecInfo(BufPtr + FRecInfoOfs)^.RecordNumber;
+    Result := unaligned(PRecInfo(BufPtr + FRecInfoOfs)^.RecordNumber);
 end;
 
 procedure TFixedFormatDataSet.SetRecNo(Value: Integer);
@@ -571,7 +571,7 @@
 begin                          // Returns true if accepted in the filter
   SaveState := SetTempState(dsFilter);
   FFilterBuffer := RecBuf;
-  PRecInfo(FFilterBuffer + FRecInfoOfs)^.RecordNumber := ARecNo;
+  unaligned(PRecInfo(FFilterBuffer + FRecInfoOfs)^.RecordNumber) := ARecNo;
   Accept := TRUE;
   if Accept and Assigned(OnFilterRecord) then
     OnFilterRecord(Self, Accept);
@@ -754,7 +754,7 @@
 var
   Index: Integer;
 begin
-  Index := FData.IndexOfObject(TObject(PPtrInt(ABookmark)^));
+  Index := FData.IndexOfObject(TObject(unaligned(PPtrInt(ABookmark)^)));
   if Index <> -1 then
     FCurRec := Index
   else
@@ -764,17 +764,17 @@
 procedure TFixedFormatDataSet.InternalSetToRecord(Buffer: PChar);
 begin
   if (State <> dsInsert) then
-    InternalGotoBookmark(@PRecInfo(Buffer + FRecInfoOfs)^.RecordNumber);
+    InternalGotoBookmark(@unaligned(PRecInfo(Buffer + FRecInfoOfs)^.RecordNumber));
 end;
 
 function TFixedFormatDataSet.GetBookmarkFlag(Buffer: PChar): TBookmarkFlag;
 begin
-  Result := PRecInfo(Buffer + FRecInfoOfs)^.BookmarkFlag;
+  Result := unaligned(PRecInfo(Buffer + FRecInfoOfs)^.BookmarkFlag);
 end;
 
 procedure TFixedFormatDataSet.SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag);
 begin
-  PRecInfo(Buffer + FRecInfoOfs)^.BookmarkFlag := Value;
+  unaligned(PRecInfo(Buffer + FRecInfoOfs)^.BookmarkFlag) := Value;
 end;
 
 procedure TFixedFormatDataSet.GetBookmarkData(Buffer: PChar; Data: Pointer);
sdfdata-unaligned.patch (2,258 bytes)   

2010-11-07 20:25

 

testsdf.pp (1,180 bytes)

Marco van de Voort

2012-05-19 12:12

manager   ~0059734

I think unaligned is correct in these cases since it is a random bytewise index in a buffer?

LacaK

2015-05-19 10:34

developer   ~0083776

I did attempt to fix "misaligned data access" error in rev.30883
Now your test program works on my WinCE 6 / XScale (ARMv5TE) device.
Can you (or sb) retest on your side please?

LacaK

2016-02-05 13:40

developer   ~0089780

Resolving as no feedback. Reopen if needed.

Issue History

Date Modified Username Field Change
2010-11-07 20:25 Sven Barth New Issue
2010-11-07 20:25 Sven Barth Status new => assigned
2010-11-07 20:25 Sven Barth Assigned To => Joost van der Sluis
2010-11-07 20:25 Sven Barth File Added: sdfdata-unaligned.patch
2010-11-07 20:25 Sven Barth File Added: testsdf.pp
2012-05-19 12:12 Marco van de Voort Note Added: 0059734
2012-06-09 15:28 Marco van de Voort Relationship added related to 0022177
2015-05-19 10:27 LacaK Assigned To Joost van der Sluis => LacaK
2015-05-19 10:34 LacaK Note Added: 0083776
2015-05-19 10:34 LacaK Status assigned => feedback
2015-08-30 22:01 Joost van der Sluis Fixed in Version => 3.0.1
2015-08-30 22:07 Jonas Maebe Fixed in Version 3.0.1 =>
2016-02-05 13:40 LacaK Fixed in Revision => 30883
2016-02-05 13:40 LacaK Note Added: 0089780
2016-02-05 13:40 LacaK Status feedback => resolved
2016-02-05 13:40 LacaK Fixed in Version => 3.0.0
2016-02-05 13:40 LacaK Resolution open => fixed