Skip to content
Snippets Groups Projects
Commit e4772831 authored by Ian Lance Taylor's avatar Ian Lance Taylor Committed by Gopher Robot
Browse files

[release-branch.go1.23] runtime/cgo: avoid errors from -Wdeclaration-after-statement

CL 652181 accidentally missed this iPhone only code.

For #71961
For #71962

Change-Id: I567f8bb38958907442e69494da330d5199d11f54
Reviewed-on: https://go-review.googlesource.com/c/go/+/653136


Reviewed-by: default avatarMichael Pratt <mpratt@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: default avatarIan Lance Taylor <iant@google.com>
parent 9facf1f2
No related branches found
No related tags found
No related merge requests found
...@@ -75,19 +75,27 @@ threadentry(void *v) ...@@ -75,19 +75,27 @@ threadentry(void *v)
static void static void
init_working_dir() init_working_dir()
{ {
CFBundleRef bundle = CFBundleGetMainBundle(); CFBundleRef bundle;
CFURLRef url_ref;
CFStringRef url_str_ref;
char buf[MAXPATHLEN];
Boolean res;
int url_len;
char *dir;
CFStringRef wd_ref;
bundle = CFBundleGetMainBundle();
if (bundle == NULL) { if (bundle == NULL) {
fprintf(stderr, "runtime/cgo: no main bundle\n"); fprintf(stderr, "runtime/cgo: no main bundle\n");
return; return;
} }
CFURLRef url_ref = CFBundleCopyResourceURL(bundle, CFSTR("Info"), CFSTR("plist"), NULL); url_ref = CFBundleCopyResourceURL(bundle, CFSTR("Info"), CFSTR("plist"), NULL);
if (url_ref == NULL) { if (url_ref == NULL) {
// No Info.plist found. It can happen on Corellium virtual devices. // No Info.plist found. It can happen on Corellium virtual devices.
return; return;
} }
CFStringRef url_str_ref = CFURLGetString(url_ref); url_str_ref = CFURLGetString(url_ref);
char buf[MAXPATHLEN]; res = CFStringGetCString(url_str_ref, buf, sizeof(buf), kCFStringEncodingUTF8);
Boolean res = CFStringGetCString(url_str_ref, buf, sizeof(buf), kCFStringEncodingUTF8);
CFRelease(url_ref); CFRelease(url_ref);
if (!res) { if (!res) {
fprintf(stderr, "runtime/cgo: cannot get URL string\n"); fprintf(stderr, "runtime/cgo: cannot get URL string\n");
...@@ -96,13 +104,13 @@ init_working_dir() ...@@ -96,13 +104,13 @@ init_working_dir()
// url is of the form "file:///path/to/Info.plist". // url is of the form "file:///path/to/Info.plist".
// strip it down to the working directory "/path/to". // strip it down to the working directory "/path/to".
int url_len = strlen(buf); url_len = strlen(buf);
if (url_len < sizeof("file://")+sizeof("/Info.plist")) { if (url_len < sizeof("file://")+sizeof("/Info.plist")) {
fprintf(stderr, "runtime/cgo: bad URL: %s\n", buf); fprintf(stderr, "runtime/cgo: bad URL: %s\n", buf);
return; return;
} }
buf[url_len-sizeof("/Info.plist")+1] = 0; buf[url_len-sizeof("/Info.plist")+1] = 0;
char *dir = &buf[0] + sizeof("file://")-1; dir = &buf[0] + sizeof("file://")-1;
if (chdir(dir) != 0) { if (chdir(dir) != 0) {
fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", dir); fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", dir);
...@@ -110,7 +118,7 @@ init_working_dir() ...@@ -110,7 +118,7 @@ init_working_dir()
// The test harness in go_ios_exec passes the relative working directory // The test harness in go_ios_exec passes the relative working directory
// in the GoExecWrapperWorkingDirectory property of the app bundle. // in the GoExecWrapperWorkingDirectory property of the app bundle.
CFStringRef wd_ref = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("GoExecWrapperWorkingDirectory")); wd_ref = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("GoExecWrapperWorkingDirectory"));
if (wd_ref != NULL) { if (wd_ref != NULL) {
if (!CFStringGetCString(wd_ref, buf, sizeof(buf), kCFStringEncodingUTF8)) { if (!CFStringGetCString(wd_ref, buf, sizeof(buf), kCFStringEncodingUTF8)) {
fprintf(stderr, "runtime/cgo: cannot get GoExecWrapperWorkingDirectory string\n"); fprintf(stderr, "runtime/cgo: cannot get GoExecWrapperWorkingDirectory string\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment