hxcpp icon indicating copy to clipboard operation
hxcpp copied to clipboard

Fix sys_stat size integer overflow

Open barisyild opened this issue 1 year ago • 11 comments

This pull request fixes the file size integer overflow issue for sys_stat.

barisyild avatar Oct 14 '24 09:10 barisyild

CI failure is related:

Error: /Users/runner/work/hxcpp/hxcpp/src/hx/libs/std/Sys.cpp:479:4: error: conversion from 'long' to 'const Dynamic' is ambiguous
   STATF64(size);

Simn avatar Oct 14 '24 09:10 Simn

CI failure is related:

Error: /Users/runner/work/hxcpp/hxcpp/src/hx/libs/std/Sys.cpp:479:4: error: conversion from 'long' to 'const Dynamic' is ambiguous
   STATF64(size);

I think Apple is a bit more strict with the type casting, the compile problem was solved.

https://github.com/barisyild/hxcpp/actions/runs/11325731311

barisyild avatar Oct 14 '24 11:10 barisyild

Note that long is 32-bit on certain platforms, it would be better to use int64_t.

Apprentice-Alchemist avatar Oct 14 '24 15:10 Apprentice-Alchemist

Can't we just always use the __APPLE__ version?

Simn avatar Oct 14 '24 15:10 Simn

Obviously nothing has changed on the apple side, but the error occurred, does anyone have any idea?

Old Commit: https://github.com/HaxeFoundation/hxcpp/pull/1157/commits/a427d1f4c5b78d35f65a21de31950f11d3aeb95f

New Commit: https://github.com/HaxeFoundation/hxcpp/pull/1157/commits/193b3d1632b72c9ba2832f51b6839a5e0d0a6c92

barisyild avatar Oct 14 '24 17:10 barisyild

Probably a bug, because the same code works fine in my ci.

https://github.com/barisyild/hxcpp/actions/runs/11331298885

barisyild avatar Oct 14 '24 17:10 barisyild

Doesn't this require a change on the haxe side to work properly? Since the FileStat typedef only has size as an Int.

Changes like this should also probably be guarded with a HXCPP_API_LEVEL check so new hxcpp versions can be used with older haxe without anything changing.

Aidan63 avatar Oct 15 '24 12:10 Aidan63

Doesn't this require a change on the haxe side to work properly? Since the FileStat typedef only has size as an Int.

Changes like this should also probably be guarded with a HXCPP_API_LEVEL check so new hxcpp versions can be used with older haxe without anything changing.

Even if there is no api change on the Haxe side, it looks fine, because haxe int actually works with float double-precision.

https://github.com/HaxeFoundation/haxe/blob/94bde7d3c00b0d1d5eabf0bbde93533c4a44b065/std/StdTypes.hx#L61

barisyild avatar Oct 15 '24 12:10 barisyild

Doesn't this require a change on the haxe side to work properly? Since the FileStat typedef only has size as an Int.

Changes like this should also probably be guarded with a HXCPP_API_LEVEL check so new hxcpp versions can be used with older haxe without anything changing.

I tried and you are right, I think it needs a haxe api change.

barisyild avatar Oct 15 '24 12:10 barisyild

https://github.com/HaxeFoundation/haxe/pull/11791

barisyild avatar Oct 15 '24 12:10 barisyild

I just tried it and it doesn't work. FileStat.size just returns 0.

SomeGuyWhoLovesCoding avatar Nov 09 '24 22:11 SomeGuyWhoLovesCoding