You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2022/12/14 20:33:06 UTC

[GitHub] [couchdb] davisp commented on a diff in pull request #4262: Show version of spidermonkey runtime in couchjs

davisp commented on code in PR #4262:
URL: https://github.com/apache/couchdb/pull/4262#discussion_r1048947263


##########
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:
   The `+ 1` on line 44 is an off by one error. The number of allocated bytes is correct, but `buf[fv_len - js_len] = '\0';` is the correct way to null-terminate that buffer.



-- 
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: notifications-unsubscribe@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org