Best Syzkaller code snippet using vcs.Swap
equip_abstract.go
Source:equip_abstract.go
...352 p.Profile.GetData().CorpCurrGS,353 func(last string) string { return p.Profile.GetLastSetCurLogicLog(last) }, "")354 return rpcSuccess(resp)355}356func (p *Account) EquipTrickSwap(r servers.Request) *servers.Response {357 req := &struct {358 Req359 AimEquipId uint32 `codec:"aid"`360 MaterialEquipId uint32 `codec:"mid"`361 }{}362 resp := &struct {363 SyncResp364 }{}365 acid := p.AccountID.String()366 initReqRsp(367 "PlayerAttr/EquipTrickSwapRsp",368 r.RawBytes, req, resp, p)369 const (370 _ = iota371 CODE_AimEquipId_Err // 失败 : AimEquipIdé误372 CODE_AimEquipData_Err // 失败 : AimEquipæè½æ°æ®é误373 CODE_AimTrickIdx_Err // 失败 : AimTrickIdxé误374 CODE_MaterialEquipId_Err // 失败 : MaterialEquipIdé误375 CODE_MaterialEquipData_Err // 失败 : MaterialEquipæè½æ°æ®é误376 CODE_Equip_Data_Err // 失败 : è£
å¤æ°æ®ç¼ºå¤±377 CODE_Part_Err // 失败 : è£
å¤ä½ç½®ä¸ä¸è´378 CODE_AimRareErr // 失败 : Aimè£
å¤çº§å«ä¸è¶³379 CODE_MatRandErr // 失败 : éæºè¿ç¨åºé380 CODE_NoMoney // 失败 : 没é±381 )382 if req.AimEquipId == req.MaterialEquipId {383 logs.Warn("EquipTrickSwap CODE_AimEquipId_Err")384 return rpcWarn(resp, errCode.ClickTooQuickly)385 }386 aim_equip := p.BagProfile.GetItem(req.AimEquipId)387 if aim_equip == nil || aim_equip.IsFixedID() {388 logs.Warn("EquipTrickSwap CODE_AimEquipId_Err")389 return rpcWarn(resp, errCode.ClickTooQuickly)390 }391 oldEquipCount := uint32(aim_equip.Count)392 mat_equip := p.BagProfile.GetItem(req.MaterialEquipId)393 if mat_equip == nil || mat_equip.IsFixedID() {394 return rpcWarn(resp, errCode.ClickTooQuickly)395 }396 oldMatCount := uint32(mat_equip.Count)397 aim_itemdata := aim_equip.GetItemData()398 if aim_itemdata == nil {399 return rpcError(resp, CODE_AimEquipData_Err)400 }401 mat_itemdata := mat_equip.GetItemData()402 if mat_itemdata == nil {403 return rpcError(resp, CODE_MaterialEquipData_Err)404 }405 // åé¨ä½å¤æ406 aim_data, aim_data_ok := gamedata.GetProtoItem(aim_equip.TableID)407 mat_data, mat_data_ok := gamedata.GetProtoItem(mat_equip.TableID)408 if !aim_data_ok || !mat_data_ok {409 return rpcError(resp, CODE_Equip_Data_Err)410 }411 if aim_data == nil || mat_data == nil {412 return rpcError(resp, CODE_Equip_Data_Err)413 }414 if aim_data.GetPart() != mat_data.GetPart() {415 logs.Warn("EquipTrickSwap CODE_Part_Err")416 return rpcWarn(resp, errCode.ClickTooQuickly)417 }418 // èè£
以ä¸419 if aim_data.GetRareLevel() < gamedata.RareLv_Blue {420 return rpcError(resp, CODE_AimRareErr)421 }422 if mat_data.GetRareLevel() < gamedata.RareLv_Blue {423 return rpcError(resp, CODE_AimRareErr)424 }425 cost := gamedata.GetEquipTrickSwapCost()426 sc_cost_ok := account.CostBySync(p.Account, cost, resp, "EquipTrickSwap")427 if !sc_cost_ok {428 return rpcError(resp, CODE_NoMoney)429 }430 logs.Trace("[%s]EquipTrickSwap %v by %v",431 acid, aim_equip, mat_equip)432 t := mat_equip.GetItemData().TrickGroup[:]433 mat_itemdata.TrickGroup = aim_itemdata.TrickGroup[:]434 aim_itemdata.TrickGroup = t435 aim_equip.SetItemData(aim_itemdata)436 p.BagProfile.UpdateItem(aim_equip)437 mat_equip.SetItemData(mat_itemdata)438 p.BagProfile.UpdateItem(mat_equip)439 p.Profile.GetData().SetNeedCheckMaxGS()440 resp.OnChangeUpdateItems(helper.Item_Inner_Type_Basic, req.AimEquipId, int64(oldEquipCount), "EquipTrickSwap")441 resp.OnChangeUpdateItems(helper.Item_Inner_Type_Basic, req.MaterialEquipId, int64(oldMatCount), "EquipTrickSwap")442 resp.mkInfo(p)443 return rpcSuccess(resp)444}...
searcher.go
Source:searcher.go
1package searcher2import (3 "fmt"4 "hound/config"5 "hound/index"6 "hound/vcs"7 "io/ioutil"8 "log"9 "os"10 "path/filepath"11 "regexp"12 "runtime"13 "sync"14 "time"15)16type Searcher struct {17 idx *index.Index18 lck sync.RWMutex19 Repo *config.Repo20}21func (s *Searcher) swapIndexes(idx *index.Index) error {22 s.lck.Lock()23 defer s.lck.Unlock()24 oldIdx := s.idx25 s.idx = idx26 return oldIdx.Destroy()27}28func (s *Searcher) Search(pat string, opt *index.SearchOptions) (*index.SearchResponse, error) {29 s.lck.RLock()30 defer s.lck.RUnlock()31 return s.idx.Search(pat, opt)32}33func (s *Searcher) GetExcludedFiles() string {34 path := filepath.Join(s.idx.GetDir(), "excluded_files.json")35 dat, err := ioutil.ReadFile(path)36 if err != nil {37 log.Printf("Couldn't read excluded_files.json %v\n", err)38 }39 return string(dat)40}41func expungeOldIndexes(sha, vcsDir string) error {42 // TODO(knorton): This is a bandaid for issue #14, but should suffice43 // since people don't usually name their repos with 40 char hashes. In44 // the longer term, I want to remove this naming scheme to support45 // rebuilds of the current hash.46 pat := regexp.MustCompile("-[0-9a-f]{40}$")47 name := fmt.Sprintf("%s-%s", filepath.Base(vcsDir), sha)48 dirs, err := filepath.Glob(fmt.Sprintf("%s-*", vcsDir))49 if err != nil {50 return err51 }52 for _, dir := range dirs {53 bn := filepath.Base(dir)54 if !pat.MatchString(bn) || len(bn) != len(name) {55 continue56 }57 if bn == name {58 continue59 }60 if err := os.RemoveAll(dir); err != nil {61 return err62 }63 }64 return nil65}66func buildAndOpenIndex(sha, vcsDir string) (*index.Index, error) {67 idxDir := fmt.Sprintf("%s-%s", vcsDir, sha)68 if _, err := os.Stat(idxDir); err != nil {69 _, err := index.Build(idxDir, vcsDir)70 if err != nil {71 return nil, err72 }73 }74 return index.Open(idxDir)75}76func reportOnMemory() {77 var ms runtime.MemStats78 // Print out interesting heap info.79 runtime.ReadMemStats(&ms)80 fmt.Printf("HeapInUse = %0.2f\n", float64(ms.HeapInuse)/1e6)81 fmt.Printf("HeapIdle = %0.2f\n", float64(ms.HeapIdle)/1e6)82}83// Creates a new Searcher for the vcsDir but avoids any remote vcs operations.84// This requires that an existing vcsDir be available in the data directory. This85// is intended for debugging and testing only. This will not start a watcher to86// monitor the remote repo for changes.87func NewFromExisting(vcsDir string, repo *config.Repo) (*Searcher, error) {88 name := filepath.Base(vcsDir)89 log.Printf("Search started for %s", name)90 log.Println(" WARNING: index is static and will not update")91 sha, err := vcs.HeadHash(repo.VCS, vcsDir)92 if err != nil {93 return nil, err94 }95 idx, err := buildAndOpenIndex(sha, vcsDir)96 if err != nil {97 return nil, err98 }99 return &Searcher{100 idx: idx,101 Repo: repo,102 }, nil103}104// Creates a new Searcher that is available for searches as soon as this returns.105// This will pull or clone the target repo and start watching the repo for changes.106func New(vcsDir string, repo *config.Repo) (*Searcher, error) {107 name := filepath.Base(vcsDir)108 log.Printf("Searcher started for %s", name)109 sha, err := vcs.PullOrClone(repo.VCS, vcsDir, repo.Url)110 if err != nil {111 return nil, err112 }113 if err := expungeOldIndexes(sha, vcsDir); err != nil {114 return nil, err115 }116 idx, err := buildAndOpenIndex(sha, vcsDir)117 if err != nil {118 return nil, err119 }120 s := &Searcher{121 idx: idx,122 Repo: repo,123 }124 go func() {125 for {126 time.Sleep(time.Duration(repo.MsBetweenPolls) * time.Millisecond)127 newSha, err := vcs.PullOrClone(repo.VCS, vcsDir, repo.Url)128 if err != nil {129 log.Printf("vcs pull error (%s - %s): %s", name, repo.Url, err)130 continue131 }132 if newSha == sha {133 continue134 }135 log.Printf("Rebuilding %s for %s", name, newSha)136 idx, err := buildAndOpenIndex(newSha, vcsDir)137 if err != nil {138 log.Printf("failed index build (%s): %s", name, err)139 os.RemoveAll(fmt.Sprintf("%s-%s", vcsDir, newSha))140 continue141 }142 if err := s.swapIndexes(idx); err != nil {143 log.Printf("failed index swap (%s): %s", name, err)144 if err := idx.Destroy(); err != nil {145 log.Printf("failed to destroy index (%s): %s\n", name, err)146 }147 continue148 }149 sha = newSha150 // This is just a good time to GC since we know there will be a151 // whole set of dead posting lists on the heap. Ensuring these152 // go away quickly helps to prevent the heap from expanding153 // uncessarily.154 runtime.GC()155 reportOnMemory()156 }157 }()158 return s, nil159}...
pbft_view_impl.go
Source:pbft_view_impl.go
...21 ViewChangeMsgs map[string]*ViewChangeMsg22 TotalViewChangeMsg int3223 ViewChangeMsgMutex sync.RWMutex24 // Flags whether VIEW-CHANGE message has broadcasted.25 // Its value is atomically swapped by CompareAndSwapInt32.26 msgSent int32 // atomic bool27}28func CreateViewChangeState(nodeID string, totNodes int, nextviewID int64, stablecheckpoint int64) *VCState {29 return &VCState{30 NextViewID: nextviewID,31 ViewChangeMsgLogs: &ViewChangeMsgLogs{32 ViewChangeMsgs:make(map[string]*ViewChangeMsg),33 TotalViewChangeMsg: 0,34 msgSent: 0,35 },36 NewViewMsg: nil,37 NodeID: nodeID,38 StableCheckPoint: stablecheckpoint,39 f: (totNodes - 1) / 3,40 }41}42func (vcs *VCState) ViewChange(viewchangeMsg *ViewChangeMsg) (*NewViewMsg, error) {43 // verify VIEW-CHANGE message.44 // TODO verity sender's signature45 //if err := vcs.verifyVCMsg(viewchangeMsg.NodeID, viewchangeMsg.NextViewID, viewchangeMsg.StableCheckPoint); err != nil {46 // return nil, errors.New("view-change message is corrupted: " + err.Error() + " (nextviewID " + fmt.Sprintf("%d", viewchangeMsg.NextViewID) + ")")47 //}48 // Append VIEW-CHANGE message to its logs.49 vcs.ViewChangeMsgLogs.ViewChangeMsgMutex.Lock()50 if _, ok := vcs.ViewChangeMsgLogs.ViewChangeMsgs[viewchangeMsg.NodeID]; ok {51 fmt.Printf("View-change message from %s is already received, next view number=%d\n",52 viewchangeMsg.NodeID, vcs.NextViewID)53 vcs.ViewChangeMsgLogs.ViewChangeMsgMutex.Unlock()54 return nil, nil55 }56 vcs.ViewChangeMsgLogs.ViewChangeMsgs[viewchangeMsg.NodeID] = viewchangeMsg57 vcs.ViewChangeMsgLogs.ViewChangeMsgMutex.Unlock()58 newTotalViewchangeMsg := atomic.AddInt32(&vcs.ViewChangeMsgLogs.TotalViewChangeMsg, 1)59 // Print current voting status.60 fmt.Printf("[View-Change-Vote]: %d\n", newTotalViewchangeMsg)61 // Return NEW-VIEW message only once.62 if int(newTotalViewchangeMsg) >= 2*vcs.f + 1 &&63 atomic.CompareAndSwapInt32(&vcs.ViewChangeMsgLogs.msgSent, 0, 1) {64 return &NewViewMsg{65 NextViewID: vcs.NextViewID,66 NodeID: vcs.NodeID,67 SetViewChangeMsgs: vcs.GetViewChangeMsgs(),68 SetPrePrepareMsgs: nil,69 Max_S: 0,70 Min_S: 0,71 }, nil72 }73 return nil, nil74}75func (vcs *VCState) GetViewChangeMsgs() map[string]*ViewChangeMsg {76 newMap := make(map[string]*ViewChangeMsg)77 vcs.ViewChangeMsgLogs.ViewChangeMsgMutex.RLock()...
Swap
Using AI Code Generation
1import (2func main() {3 fmt.Println("Before swapping")4 fmt.Println("a = ", a, "b = ", b)5 vcs.Swap(&a, &b)6 fmt.Println("After swapping")7 fmt.Println("a = ", a, "b = ", b)8}9func Swap(a *int, b *int) {10}11type User struct {12}13func (u *User) UpdateName(newName string) {14}15func (u *User) UpdateAge(newAge int) {16}17func (u *User) PrintUser() {18 fmt.Println("Name:", u.name)19 fmt.Println("Age:", u.age)20}21import (22func main() {23 user := vcs.User{name: "John", age: 20}24 user.PrintUser()25 user.UpdateName("Jane")26 user.UpdateAge(21)27 user.PrintUser()28}
Swap
Using AI Code Generation
1vcs.Swap(3, 5);2vcs.Swap(2, 4);3vcs.Swap(1, 2);4vcs.Swap(4, 5);5vcs.Swap(2, 3);6vcs.Swap(1, 2);7vcs.Swap(4, 5);8vcs.Swap(1, 2);9vcs.Swap(3, 5);10vcs.Swap(1, 3);11vcs.Swap(2, 4);12vcs.Swap(1, 2);13vcs.Swap(4, 5);14vcs.Swap(2, 3);15vcs.Swap(1, 2);16vcs.Swap(4, 5);17vcs.Swap(1, 2);18vcs.Swap(3, 5);19vcs.Swap(1, 3);20vcs.Swap(2, 4);21vcs.Swap(1, 2);22vcs.Swap(4, 5);23vcs.Swap(2, 3);24vcs.Swap(1, 2);
Swap
Using AI Code Generation
1import (2func main() {3 fmt.Println("Enter two numbers")4 fmt.Scanf("%d %d", &a, &b)5 vcs.Swap(a, b)6}7import "fmt"8func Swap(a, b int) {9 fmt.Println("After swap a =", a, "b =", b)10}
Swap
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 v:=vcs.NewVector(1,2)5 v.Swap()6 fmt.Println(v)7}8type Vector struct{9}10func (v *Vector) Swap(){11}12func NewVector(x,y float64) *Vector{13 return &Vector{x,y}14}15I am trying to use the Swap() method of the Vector class in the main package. I am getting the error "cannot refer to unexported name vcs.Vector" . I am not able to understand why this is happening. Can anyone help me with this?
Swap
Using AI Code Generation
1import (2func main() {3 v := vcs{1, 2}4 fmt.Println("Before swap: ", v)5 v.swap()6 fmt.Println("After swap: ", v)7}8Before swap: {1 2}9After swap: {2 1}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!