all: Fix check for empty string (#8456)

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
This commit is contained in:
deepsource-autofix[bot] 2022-07-28 16:51:03 +02:00 committed by GitHub
parent a2c5d901f2
commit 80ec4acb53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 13 additions and 13 deletions

View File

@ -90,7 +90,7 @@ func handleFailureFn(dsn, failureDir string) func(w http.ResponseWriter, req *ht
for k, v := range r.Extra { for k, v := range r.Extra {
pkt.Extra[k] = v pkt.Extra[k] = v
} }
if len(r.Goroutines) != 0 { if r.Goroutines != "" {
url, err := saveFailureWithGoroutines(r.FailureData, failureDir) url, err := saveFailureWithGoroutines(r.FailureData, failureDir)
if err != nil { if err != nil {
log.Println("Saving failure report:", err) log.Println("Saving failure report:", err)

View File

@ -647,7 +647,7 @@ func syncthingMain(options serveOptions) {
setupSignalHandling(app) setupSignalHandling(app)
if len(os.Getenv("GOMAXPROCS")) == 0 { if os.Getenv("GOMAXPROCS") == "" {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
} }

View File

@ -16,7 +16,7 @@ import (
func ParseSize(s string) (Size, error) { func ParseSize(s string) (Size, error) {
s = strings.TrimSpace(s) s = strings.TrimSpace(s)
if len(s) == 0 { if s == "" {
return Size{}, nil return Size{}, nil
} }

View File

@ -64,7 +64,7 @@ func NewLocal(id protocol.DeviceID, addr string, addrList AddressLister, evLogge
return nil, err return nil, err
} }
if len(host) == 0 { if host == "" {
// A broadcast client // A broadcast client
c.name = "IPv4 local" c.name = "IPv4 local"
bcPort, err := strconv.Atoi(port) bcPort, err := strconv.Atoi(port)

View File

@ -55,7 +55,7 @@ func WindowsInvalidFilename(name string) error {
// None of the path components should end in space or period, or be a // None of the path components should end in space or period, or be a
// reserved name. // reserved name.
for _, part := range strings.Split(name, `\`) { for _, part := range strings.Split(name, `\`) {
if len(part) == 0 { if part == "" {
continue continue
} }
switch part[len(part)-1] { switch part[len(part)-1] {

View File

@ -737,7 +737,7 @@ func (f *sendReceiveFolder) handleSymlink(file protocol.FileInfo, snap *db.Snaps
l.Debugf("need symlink\n\t%v\n\t%v", file, curFile) l.Debugf("need symlink\n\t%v\n\t%v", file, curFile)
} }
if len(file.SymlinkTarget) == 0 { if file.SymlinkTarget == "" {
// Index entry from a Syncthing predating the support for including // Index entry from a Syncthing predating the support for including
// the link target in the index entry. We log this as an error. // the link target in the index entry. We log this as an error.
f.newPullError(file.Name, errIncompatibleSymlink) f.newPullError(file.Name, errIncompatibleSymlink)

View File

@ -511,7 +511,7 @@ func (m *model) cleanupFolderLocked(cfg config.FolderConfiguration) {
} }
func (m *model) restartFolder(from, to config.FolderConfiguration, cacheIgnoredFiles bool) error { func (m *model) restartFolder(from, to config.FolderConfiguration, cacheIgnoredFiles bool) error {
if len(to.ID) == 0 { if to.ID == "" {
panic("bug: cannot restart empty folder ID") panic("bug: cannot restart empty folder ID")
} }
if to.ID != from.ID { if to.ID != from.ID {

View File

@ -547,7 +547,7 @@ func slashify(s string) string {
// deslashify removes slashes and encrypted file extensions from the string. // deslashify removes slashes and encrypted file extensions from the string.
// This is the inverse of slashify(). // This is the inverse of slashify().
func deslashify(s string) (string, error) { func deslashify(s string) (string, error) {
if len(s) == 0 || !strings.HasPrefix(s[1:], encryptedDirExtension) { if s == "" || !strings.HasPrefix(s[1:], encryptedDirExtension) {
return "", fmt.Errorf("invalid encrypted path: %q", s) return "", fmt.Errorf("invalid encrypted path: %q", s)
} }
s = s[:1] + s[1+len(encryptedDirExtension):] s = s[:1] + s[1+len(encryptedDirExtension):]
@ -575,7 +575,7 @@ func IsEncryptedParent(pathComponents []string) bool {
} else if l == 0 { } else if l == 0 {
return false return false
} }
if len(pathComponents[0]) == 0 { if pathComponents[0] == "" {
return false return false
} }
if pathComponents[0][1:] != encryptedDirExtension { if pathComponents[0][1:] != encryptedDirExtension {

View File

@ -748,12 +748,12 @@ func TestStopWalk(t *testing.T) {
f := res.File f := res.File
t.Log("Scanned", f) t.Log("Scanned", f)
if f.IsDirectory() { if f.IsDirectory() {
if len(f.Name) == 0 || f.Permissions == 0 { if f.Name == "" || f.Permissions == 0 {
t.Error("Bad directory entry", f) t.Error("Bad directory entry", f)
} }
dirs++ dirs++
} else { } else {
if len(f.Name) == 0 || len(f.Blocks) == 0 || f.Permissions == 0 { if f.Name == "" || len(f.Blocks) == 0 || f.Permissions == 0 {
t.Error("Bad file entry", f) t.Error("Bad file entry", f)
} }
files++ files++

View File

@ -383,7 +383,7 @@ func getIGDServices(deviceUUID string, localIPAddress net.IP, rootURL string, de
l.Debugln(rootURL, "- no services of type", URN, " found on connection.") l.Debugln(rootURL, "- no services of type", URN, " found on connection.")
for _, service := range services { for _, service := range services {
if len(service.ControlURL) == 0 { if service.ControlURL == "" {
l.Infoln(rootURL+"- malformed", service.Type, "description: no control URL.") l.Infoln(rootURL+"- malformed", service.Type, "description: no control URL.")
} else { } else {
u, _ := url.Parse(rootURL) u, _ := url.Parse(rootURL)

View File

@ -410,7 +410,7 @@ func clear(v interface{}, since int) error {
tag := t.Field(i).Tag tag := t.Field(i).Tag
v := tag.Get("since") v := tag.Get("since")
if len(v) == 0 { if v == "" {
f.Set(reflect.Zero(f.Type())) f.Set(reflect.Zero(f.Type()))
continue continue
} }