Skip to content

ESP32 FILE_WRITE overflow: O_APPEND and O_CREAT is defined different #151

Open
@MaDill

Description

@MaDill

I have a strange error. I port my code from an arduino uno to ans ESP32. I use the SD library version 1.2.4

When I want to open a file with mode FILE_WRITE I receive a compiler error:

"message": "unsigned conversion from 'int' to 'uint8_t' {aka 'unsigned char'} changes value from '523' to '11' [-Woverflow]",
"startLineNumber": 24,
"startColumn": 48,
"endLineNumber": 24,
"endColumn": 48

(O_READ | O_WRITE | O_CREAT | O_APPEND) is defined in SdFat.h as

uint8_t const O_READ = 0X01;
uint8_t const O_WRITE = 0X02;
uint8_t const O_CREAT = 0X10;
uint8_t const O_APPEND = 0X04;

Should be 23 (DEC)

I then tried to create the FILE_WRITE by myself and see in VSCode that it is expanded to:

O_READ = 1
O_WRITE = 2
O_CREAT = 0x0200
O_APPEND = 0x0008

and this is 523 (DEC)

The used O_CREATE is from:
.platformio\packages\toolchain-xtensa-esp32\xtensa-esp32-elf\sys-include\sys\_default_fcntl.h
line 51:

#define	O_APPEND	_FAPPEND

line 52:

#define	O_CREAT		_FCREAT

line 12:

#define	_FAPPEND	0x0008	/* append (writes guaranteed at the end) */

line 18:

#define	_FCREAT		0x0200	/* open with file create */

This is from my platformio.ini:

platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
	arduino-libraries/SD@^1.2.4
	fbiego/ESP32Time @ ^2.0.6
check_skip_packages = yes

Installed is https://github.com/platformio/platform-espressif32 in version 6.6.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions