From 2542c55e9d4863a7d220ecea7f82d7764e45abf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 25 Aug 2019 16:26:59 +0100 Subject: [PATCH] all: fix some issues spotted by static analysis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First, vet was upset by two incorrect fmt verbs. One was an extra %x, when there was just one argument, so remove it. Another was a %p with a non-pointer. It's a struct, so for now simply use %#v. Second, staticcheck found some unused or unnecessary bits of code; remove the obvious ones. Finally, staticcheck also complained about some error strings which were capitalized or had periods. Adjust those, which also makes all error messages more consistent. Signed-off-by: Daniel Martí --- apps/gophers/ui.go | 1 - cmd/gio/androidbuild.go | 10 +++++----- ui/app/egl.go | 2 +- ui/app/internal/gpu/caches.go | 2 +- ui/app/internal/gpu/gpu.go | 2 +- ui/app/window.go | 2 +- ui/internal/ops/reader.go | 1 - 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/gophers/ui.go b/apps/gophers/ui.go index 046f2d32..5c40a859 100644 --- a/apps/gophers/ui.go +++ b/apps/gophers/ui.go @@ -58,7 +58,6 @@ type UI struct { } type userPage struct { - config ui.Config faces measure.Faces user *user commitsList *layout.List diff --git a/cmd/gio/androidbuild.go b/cmd/gio/androidbuild.go index 6420b27b..8ff7b7e1 100644 --- a/cmd/gio/androidbuild.go +++ b/cmd/gio/androidbuild.go @@ -38,7 +38,7 @@ type errWriter struct { func buildAndroid(tmpDir string, bi *buildInfo) error { sdk := os.Getenv("ANDROID_HOME") if sdk == "" { - return errors.New("Please set ANDROID_HOME to the Android SDK path") + return errors.New("please set ANDROID_HOME to the Android SDK path") } if _, err := os.Stat(sdk); err != nil { return err @@ -75,11 +75,11 @@ func buildAndroid(tmpDir string, bi *buildInfo) error { func compileAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err error) { androidHome := os.Getenv("ANDROID_HOME") if androidHome == "" { - return errors.New("ANDROID_HOME is not set. Please point it to the root of the Android SDK.") + return errors.New("ANDROID_HOME is not set. Please point it to the root of the Android SDK") } ndkRoot := filepath.Join(androidHome, "ndk-bundle") if _, err := os.Stat(ndkRoot); err != nil { - return fmt.Errorf("No NDK found in $ANDROID_HOME/ndk-bundle (%s). Use `sdkmanager ndk-bundle` to install it.", ndkRoot) + return fmt.Errorf("no NDK found in $ANDROID_HOME/ndk-bundle (%s). Use `sdkmanager ndk-bundle` to install it", ndkRoot) } tcRoot := filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK()) var builds errgroup.Group @@ -87,7 +87,7 @@ func compileAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err erro arch := allArchs[a] clang := filepath.Join(tcRoot, "bin", arch.clang) if _, err := os.Stat(clang); err != nil { - return fmt.Errorf("No NDK compiler found. Please make sure you have NDK >= r19c installed. Use the command `sdkmanager ndk-bundle` to install it. Path %s", clang) + return fmt.Errorf("no NDK compiler found. Please make sure you have NDK >= r19c installed. Use the command `sdkmanager ndk-bundle` to install it. Path %s", clang) } if runtime.GOOS == "windows" { // Because of https://github.com/android-ndk/ndk/issues/920, @@ -95,7 +95,7 @@ func compileAndroid(tmpDir string, tools *androidTools, bi *buildInfo) (err erro // clang++.cmd which is only available in r19c. clangpp := filepath.Join(tcRoot, "bin", arch.clang+"++.cmd") if _, err := os.Stat(clangpp); err != nil { - return fmt.Errorf("NDK version r19b detected, but >= r19c is required. Use the command `sdkmanager ndk-bundle` to install it.") + return fmt.Errorf("NDK version r19b detected, but >= r19c is required. Use the command `sdkmanager ndk-bundle` to install it") } } archDir := filepath.Join(tmpDir, "jni", arch.jniArch) diff --git a/ui/app/egl.go b/ui/app/egl.go index d4496262..98a412ec 100644 --- a/ui/app/egl.go +++ b/ui/app/egl.go @@ -89,7 +89,7 @@ func (c *context) Present() error { c.srgbFBO.Blit() } if !eglSwapBuffers(c.eglCtx.disp, c.eglSurf) { - return fmt.Errorf("eglSwapBuffers failed (%x%x)", eglGetError()) + return fmt.Errorf("eglSwapBuffers failed (%x)", eglGetError()) } if c.srgbFBO != nil { c.srgbFBO.AfterPresent() diff --git a/ui/app/internal/gpu/caches.go b/ui/app/internal/gpu/caches.go index 92bd740b..3ede6575 100644 --- a/ui/app/internal/gpu/caches.go +++ b/ui/app/internal/gpu/caches.go @@ -81,7 +81,7 @@ func (r *opCache) get(key ops.Key) (resource, bool) { func (r *opCache) put(key ops.Key, val resource) { if _, exists := r.newRes[key]; exists { - panic(fmt.Errorf("key exists, %p", key)) + panic(fmt.Errorf("key exists, %#v", key)) } r.res[key] = val r.newRes[key] = val diff --git a/ui/app/internal/gpu/gpu.go b/ui/app/internal/gpu/gpu.go index 9392a976..9ea8a35b 100644 --- a/ui/app/internal/gpu/gpu.go +++ b/ui/app/internal/gpu/gpu.go @@ -349,7 +349,7 @@ func (g *GPU) renderLoop(glctx gl.Context) error { zt, st, covt, cleant := zopsTimer.Elapsed, stencilTimer.Elapsed, coverTimer.Elapsed, cleanupTimer.Elapsed ft := zt + st + covt + cleant q := 100 * time.Microsecond - zt, st, covt, cleant = zt.Round(q), st.Round(q), covt.Round(q), cleant.Round(q) + zt, st, covt = zt.Round(q), st.Round(q), covt.Round(q) ft = ft.Round(q) res.summary = fmt.Sprintf("f:%7s zt:%7s st:%7s cov:%7s", ft, zt, st, covt) } diff --git a/ui/app/window.go b/ui/app/window.go index 8fa39724..51b016ec 100644 --- a/ui/app/window.go +++ b/ui/app/window.go @@ -361,4 +361,4 @@ func WithHeight(h ui.Value) WindowOption { } } -func (_ driverEvent) ImplementsEvent() {} +func (driverEvent) ImplementsEvent() {} diff --git a/ui/internal/ops/reader.go b/ui/internal/ops/reader.go index 80abb869..c4f35810 100644 --- a/ui/internal/ops/reader.go +++ b/ui/internal/ops/reader.go @@ -33,7 +33,6 @@ type Key struct { // Shadow of ui.MacroOp. type macroOp struct { - recording bool ops *ui.Ops version int pc pc