Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

Serial port name init seems wrong/strange #6

Closed
Apollon77 opened this issue Mar 14, 2018 · 1 comment
Closed

Serial port name init seems wrong/strange #6

Apollon77 opened this issue Mar 14, 2018 · 1 comment

Comments

@Apollon77
Copy link

Hi again :-)

I found one last thing which adding testing for my library.

Your code in "OpenSerial" to init ihe port name is:

com.port = calloc(1,sizeof(char)*(strlen("\\\\.\\")+4));
strncat(com.port, portname, 4);

So you only accept the first 4 characters of the portname that is given to the function, but reserve then 4 bytes more without writing them somewhere.

From specs:

  • You can use COM1..9 directly
  • for others (like COM10 or other names) you need to use \.\COM10 as example.

So I think you initially wanted to limit to 4 character ports (but with this you do not allow COM10 or such) and wanted to always add "\." in front ... but you did not done that :-)

I would propose a change to:

	com.port = calloc(1,sizeof(char)*(strlen(portname)+1));
	strncat(com.port, portname, strlen(portname));

so simply copy the portname as it was as it came in (plus 1 for the \0 as string terminator) and have people send correct portnames ?!
Alternative would be to use portname as is (to also allow longer portnmes then 4 characters) and always prepend "\.". What do you think?

@veeso
Copy link
Owner

veeso commented Apr 7, 2018

Solved, it now supports both COM with one or two digits. (COMx -> COMxx)

@veeso veeso closed this as completed Apr 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants