Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Go: False positive when use sync.Map #18916

Copy link
Copy link
Open
@sud0why

Description

@sud0why
Issue body actions

Description

I think the sync.Map.Store operation should not propagate the key to the sync.Map, and the same applies to sync.Map.LoadOrStore and sync.Map.Swap. This could lead to situations where keys might propagate into values through the sync.Map.

Modifications may be needed in the ext/sync.model.yml model definition file within the go-all library.

Example Code

package mytest

import (
	"fmt"
	"net/http"
	"sync"

	"gorm.io/gorm"
)

var myMap sync.Map
var db gorm.DB

func handler(req *http.Request) {
	input := req.URL.Query().Get("input")
	value := getData(input)
	fmt.Println(value)
}

func process() {
	key := "hello"
	value := getData(key)
	db.Exec(value)
}

func getData(key string) string {
	if value, ok := myMap.Load(key); ok {
		return value.(string)
	}
	value := "hello"
	myMap.Store(key, value)
	return value
}

Result

Image

Image

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.