phoenix-rtos / phoenix-rtos-project

Sample project using Phoenix-RTOS
https://phoenix-rtos.com
BSD 3-Clause "New" or "Revised" License
43 stars 32 forks source link

ptrdiff_t length modifier for *scanf problem #617

Closed maska989 closed 1 year ago

maska989 commented 1 year ago

During scanf tests there was a problem reading data assigned as ptrdiff_t ("%t*") .

include

int main(void) { char str[125];

sprintf(str,"%td",PTRDIFF_MAX);

ptrdiff_t val;
ptrdiff_t val1;

printf("\n td = %s",str);

sscanf(str,"%td",&val);
printf("\nval with *td = %td",val);

sscanf("2147483647","%td",&val1);
printf("\nfinger val with *td = %td",val1);

sscanf("2147483647","%ld",&val1);
printf("\nfinger val with *ld = %ld",val1);

}



Outcome on Host-generic-pc  and ia32-generic-qemu:

![Screenshot from 2023-02-22 11-42-53](https://user-images.githubusercontent.com/49757239/220597260-c4b748d8-dd93-4eb5-89c4-18bc68df9c84.png)
gerard5 commented 1 year ago

@maska989 the above pull-request should resolve this issue, please verify before merge: 2023-02-23-001515_465x130_scrot

maska989 commented 1 year ago

@gerard5 After applying your pull-request everything works fine. Thanks.