Skip to content
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

reading settings option list (getSettingInfo) fails using C if no option names set #377

Closed
ahopper opened this issue Oct 3, 2022 · 5 comments · Fixed by #378
Closed

Comments

@ahopper
Copy link
Contributor

ahopper commented Oct 3, 2022

if the settings optionNames is not populated this

out.optionNames = toStrArray(info.optionNames, &out.numOptions);

resets the numOptions to 0 so the C api cannot see the options.

the lime driver has an example of not setting optionNames

https://github.com/myriadrf/LimeSuite/blob/e829d3ede6222c1c0fc0e90dcd2050e50569e33d/SoapyLMS7/Settings.cpp#L802-L807

@zuckschwerdt
Copy link
Member

Just swappig the toStrArray() call order for out.options and out.optionNames should work right?
With options last it will take precedence over the result from optionNames -- a comment to the intention is then also needed ;)
Do you want to PR this change?

@ahopper
Copy link
Contributor Author

ahopper commented Oct 3, 2022

Yep that should work, I'm happy to create a PR.

@ericek111
Copy link
Contributor

Now, if the option names are not supplied (as they are optional), the optionNames list is not properly initialized, causing a crash upon reading the junk char*s. :D

Honestly, I'd just shove size_t numOptionNames into the SoapySDRArgInfo struct, but that would break ABI. Another option is to pre-fill the names with NULLs (sizeof(char*) * out.numOptions, as returned for the options list):

-static inline char **toStrArray(const std::vector<std::string> &strs, size_t *length)
-{
-    auto out = callocArrayType<char *>(strs.size());
+static inline char **toStrArray(const std::vector<std::string> &strs, size_t *length, size_t minLength = 0)
+{
+    auto out = callocArrayType<char *>(std::max(minLength, strs.size()));

What do you think?

@zuckschwerdt
Copy link
Member

Good point and a nice fix indeed. PR if you like.
Please include e.g. …size of the options and optionNames set, …
at https://github.com/pothosware/SoapySDR/blob/master/include/SoapySDR/Types.h#L94
and When null or emtpy, the option value…
at https://github.com/pothosware/SoapySDR/blob/master/include/SoapySDR/Types.h#L105

@guruofquality
Copy link
Contributor

Another way would be to copy options into optionNames when the info.optionNames is empty. Any app looking for a displayable name for the option would just use the option string itself if optionNames was empty.

ericek111 added a commit to ericek111/SoapySDR that referenced this issue Dec 21, 2024
… provided

This prevents clients from reading junk values, as the optionNames array
is also optional.
See: pothosware#377 (comment)
ericek111 added a commit to ericek111/SoapySDR that referenced this issue Dec 21, 2024
This prevents clients from reading junk values, as the optionNames
array is also optional.

pothosware#377 (comment)
ericek111 added a commit to ericek111/SoapySDR that referenced this issue Dec 21, 2024
This prevents clients from reading junk values, as the optionNames
array is also optional.

pothosware#377 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants