davisp commented on code in PR #4262:
URL: https://github.com/apache/couchdb/pull/4262#discussion_r1048954360
##########
src/couch/priv/couch_js/86/util.cpp:
##########
@@ -26,6 +26,29 @@
#include "help.h"
#include "util.h"
+const char*
+get_spidermonkey_version() {
+ const char *JAVASCRIPT = "JavaScript-C";
+ int js_len = strlen(JAVASCRIPT);
+
+ // JS_GetImplementationVersion()
+ // returns "JavaScript-CMAJOR.MINOR.PATCH"
+ const char *FULLVERSION = JS_GetImplementationVersion();
+ int fv_len = strlen(FULLVERSION);
+
+ const char* foundJSString = strstr(FULLVERSION,JAVASCRIPT);
+ if (foundJSString != NULL) {
+ //trim off "JavaScript-C",
+ char *buf = (char*) calloc(fv_len - js_len + 1, sizeof(char));
+ strncpy(buf, &FULLVERSION[js_len], fv_len - js_len);
+ buf[fv_len - js_len + 1] = '\0';
Review Comment:
Also @nickva just pointed out that `calloc` zeroes out the returned memory
so I'd suggest either replacing the manual null termination with a note
reminding readers that `calloc` zeroes everything out. Normally, I'd also
suggest switching to malloc since you're immediately touching every byte that
was allocated before returning the string so having calloc zero everything out
is wasted work, but given the location and purpose here that's shouldn't be an
issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]