{"action":"created","issue":{"url":"https://api.github.com/repos/swig/swig/issues/1281","repository_url":"https://api.github.com/repos/swig/swig","labels_url":"https://api.github.com/repos/swig/swig/issues/1281/labels{/name}","comments_url":"https://api.github.com/repos/swig/swig/issues/1281/comments","events_url":"https://api.github.com/repos/swig/swig/issues/1281/events","html_url":"https://github.com/swig/swig/issues/1281","id":337691646,"node_id":"MDU6SXNzdWUzMzc2OTE2NDY=","number":1281,"title":"Generated code for function returning jbyteArray fails with \"error C4703: potentially uninitialized local pointer variable 'result' used\"","user":{"login":"wheezil","id":13988745,"node_id":"MDQ6VXNlcjEzOTg4NzQ1","avatar_url":"https://avatars1.githubusercontent.com/u/13988745?v=4","gravatar_id":"","url":"https://api.github.com/users/wheezil","html_url":"https://github.com/wheezil","followers_url":"https://api.github.com/users/wheezil/followers","following_url":"https://api.github.com/users/wheezil/following{/other_user}","gists_url":"https://api.github.com/users/wheezil/gists{/gist_id}","starred_url":"https://api.github.com/users/wheezil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wheezil/subscriptions","organizations_url":"https://api.github.com/users/wheezil/orgs","repos_url":"https://api.github.com/users/wheezil/repos","events_url":"https://api.github.com/users/wheezil/events{/privacy}","received_events_url":"https://api.github.com/users/wheezil/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-02T23:03:38Z","updated_at":"2018-07-04T19:13:15Z","closed_at":null,"author_association":"NONE","body":"Using SWIG on Windows:\r\n\r\n    $ swig -version\r\n    SWIG Version 3.0.12\r\n    Compiled with i686-w64-mingw32-g++ [i686-w64-mingw32]\r\n    Configured options: +pcre\r\n\r\nWhen processing this SWIG file CppService.i:\r\n\r\n    %include \"various.i\"\r\n    %module CppServiceWrap\r\n    %{\r\n       #include \"../cpp/rabbitmq_protobuf_test/CppService.h\"\r\n       #include \"../cpp/rabbitmq_protobuf_test/DL_JVM.h\"\r\n    %}\r\n    %javaexception(\"net.redpoint.hapoc.ErrorException\") {\r\n       try {\r\n          $function\r\n       } catch (...) {\r\n          Acme::DMJVM::CppToJavaException();\r\n       }\r\n    }\r\n    %include \"../cpp/rabbitmq_protobuf_test/CppService.h\"\r\n\r\nWhere CppService.h is:\r\n\r\n    #include <jni.h>\r\n    class CppService {\r\n    public:\r\n       jbyteArray call(jbyteArray bytes);\r\n    };\r\n\r\nAnd the declaration for CppToJavaException():\r\n\r\n    void CppToJavaException();\r\n\r\nThe generated code is as follows, and indeed the result is potentially uninitialized:\r\n\r\n    SWIGEXPORT jbyteArray JNICALL Java_net_redpoint_hapoc_CppServiceWrapJNI_CppService_1call(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2) {\r\n      jbyteArray jresult = 0 ;\r\n      CppService *arg1 = (CppService *) 0 ;\r\n      jbyteArray arg2 ;\r\n      jbyteArray result;\r\n      \r\n      (void)jenv;\r\n      (void)jcls;\r\n      (void)jarg1_;\r\n      arg1 = *(CppService **)&jarg1; \r\n      arg2 = jarg2; \r\n      {\r\n        try {\r\n          result = (arg1)->call(arg2);\r\n        } catch (...) {\r\n          Acme::DMJVM::CppToJavaException();\r\n        }\r\n      }\r\n      jresult = result;    // ERROR IS HERE\r\n      return jresult;\r\n    }\r\n"},"comment":{"url":"https://api.github.com/repos/swig/swig/issues/comments/402545344","html_url":"https://github.com/swig/swig/issues/1281#issuecomment-402545344","issue_url":"https://api.github.com/repos/swig/swig/issues/1281","id":402545344,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjU0NTM0NA==","user":{"login":"wheezil","id":13988745,"node_id":"MDQ6VXNlcjEzOTg4NzQ1","avatar_url":"https://avatars1.githubusercontent.com/u/13988745?v=4","gravatar_id":"","url":"https://api.github.com/users/wheezil","html_url":"https://github.com/wheezil","followers_url":"https://api.github.com/users/wheezil/followers","following_url":"https://api.github.com/users/wheezil/following{/other_user}","gists_url":"https://api.github.com/users/wheezil/gists{/gist_id}","starred_url":"https://api.github.com/users/wheezil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wheezil/subscriptions","organizations_url":"https://api.github.com/users/wheezil/orgs","repos_url":"https://api.github.com/users/wheezil/repos","events_url":"https://api.github.com/users/wheezil/events{/privacy}","received_events_url":"https://api.github.com/users/wheezil/received_events","type":"User","site_admin":false},"created_at":"2018-07-04T19:13:15Z","updated_at":"2018-07-04T19:13:15Z","author_association":"NONE","body":"So clearly the issue has to do with the try/catch block and the possibility that the catch clause will bypass the setting of result.  However, I cannot figure out how to work around this.  It is necessary for our application to translate C++ exceptions to Java exceptions, using the JNI call:\r\n    env->ThrowNew(exceptionClass, message);\r\nThat's basically what CppToJavaException() does.  I can't just assign result=0 in the catch because not all methods return values.  I suppose that I _could_ change all my methods to return values, even if unused, but that seem rather hackish."}}
{"actor":{"display_login":"wheezil"}}