-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ATParser could not support some strings very well. #7
Comments
Duplicated issue with #1: |
@tz-arm According to this (http://www.cplusplus.com/reference/cstdio/scanf/), it looks like the 15 in that formatter is considered the "width." This is what that document says about width:
So, this operation is not greedy. |
I saw ESP8266 driver and PPPCellularInterface are using this "width" parameters. |
I would actually use this: _parser.recv("%15[^\r]%*[\r]%*[\n]") The 15 protects against buffer overflow if you accidentally end up reading corrupt data. But @sarahmarshy is right this only specifies the max. The way the ATParser calls scanf makes the match non-greedy, which is a bit counter-intuitive if you're familiar with regex, where greedy matches are the norm. Non-greedy matching means you will need to explicitly indicate what stops the pattern, in this case the pattern |
I am working to integrate a NBIoT module and found that this ATParser could not support some strings.
After debugging, I found it is caused by the poor sscanf().
For example,
_parser.recv("\"%15[^\n]\"", dev_info.imsi);
from ESP8266 driver as reference , it could work._parser.recv("%15[^\n]", dev_info.imsi);
with no quotes does not work well. it will return the first char in the string to imsi.Below is a simple test code, would you help to share comments if any idea?
The text was updated successfully, but these errors were encountered: