Skip to content

Commit d1f33ab

Browse files
committed
fix incorrect usage of formatted string
output probably unchanged, but now `go vet` is happy that formatted strings are not misused
1 parent 187d114 commit d1f33ab

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

cmd/csaf_checker/processor.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ func (p *processor) rolieFeedEntries(feed string) ([]csaf.AdvisoryFile, error) {
536536
if len(errors) > 0 {
537537
p.badProviderMetadata.error("%s: Validating against JSON schema failed:", feed)
538538
for _, msg := range errors {
539-
p.badProviderMetadata.error(strings.ReplaceAll(msg, `%`, `%%`))
539+
p.badProviderMetadata.error("%s", strings.ReplaceAll(msg, `%`, `%%`))
540540
}
541541
}
542542

@@ -736,15 +736,15 @@ func (p *processor) integrity(
736736

737737
switch date, fault := p.extractTime(doc, `initial_release_date`, u); {
738738
case fault != "":
739-
p.badFolders.error(fault)
739+
p.badFolders.error("%s", fault)
740740
case folderYear == nil:
741741
p.badFolders.error("No year folder found in %s", u)
742742
case date.UTC().Year() != *folderYear:
743743
p.badFolders.error("%s should be in folder %d", u, date.UTC().Year())
744744
}
745745
current, fault := p.extractTime(doc, `current_release_date`, u)
746746
if fault != "" {
747-
p.badChanges.error(fault)
747+
p.badChanges.error("%s", fault)
748748
} else {
749749
p.timesAdv[f.URL()] = current
750750
}
@@ -814,7 +814,7 @@ func (p *processor) integrity(
814814
msgType = InfoType
815815
}
816816
for _, fetchError := range hashFetchErrors {
817-
p.badIntegrities.add(msgType, fetchError)
817+
p.badIntegrities.add(msgType, "%s", fetchError)
818818
}
819819

820820
// Check signature
@@ -1052,7 +1052,7 @@ func (p *processor) checkChanges(base string, mask whereType) error {
10521052
if p.cfg.Range != nil {
10531053
filtered = " (maybe filtered out by time interval)"
10541054
}
1055-
p.badChanges.warn("no entries in changes.csv found" + filtered)
1055+
p.badChanges.warn("%s", "no entries in changes.csv found"+filtered)
10561056
}
10571057

10581058
if !sort.SliceIsSorted(times, func(i, j int) bool {
@@ -1300,8 +1300,8 @@ func (p *processor) checkProviderMetadata(domain string) bool {
13001300

13011301
for i := range lpmd.Messages {
13021302
p.badProviderMetadata.warn(
1303-
"Unexpected situation while loading provider-metadata.json: " +
1304-
lpmd.Messages[i].Message)
1303+
"Unexpected situation while loading provider-metadata.json: %s",
1304+
lpmd.Messages[i].Message)
13051305
}
13061306

13071307
if !lpmd.Valid() {
@@ -1401,25 +1401,25 @@ func (p *processor) checkDNS(domain string) {
14011401
res, err := client.Get(path)
14021402
if err != nil {
14031403
p.badDNSPath.add(ErrorType,
1404-
fmt.Sprintf("Fetching %s failed: %v", path, err))
1404+
"Fetching %s failed: %v", path, err)
14051405
return
14061406
}
14071407
if res.StatusCode != http.StatusOK {
1408-
p.badDNSPath.add(ErrorType, fmt.Sprintf("Fetching %s failed. Status code %d (%s)",
1409-
path, res.StatusCode, res.Status))
1408+
p.badDNSPath.add(ErrorType, "Fetching %s failed. Status code %d (%s)",
1409+
path, res.StatusCode, res.Status)
14101410
}
14111411
hash := sha256.New()
14121412
defer res.Body.Close()
14131413
content, err := io.ReadAll(res.Body)
14141414
if err != nil {
14151415
p.badDNSPath.add(ErrorType,
1416-
fmt.Sprintf("Error while reading the response from %s", path))
1416+
"Error while reading the response from %s", path)
14171417
}
14181418
hash.Write(content)
14191419
if !bytes.Equal(hash.Sum(nil), p.pmd256) {
14201420
p.badDNSPath.add(ErrorType,
1421-
fmt.Sprintf("%s does not serve the same provider-metadata.json as previously found",
1422-
path))
1421+
"%s does not serve the same provider-metadata.json as previously found",
1422+
path)
14231423
}
14241424
}
14251425

@@ -1433,12 +1433,12 @@ func (p *processor) checkWellknown(domain string) {
14331433
res, err := client.Get(path)
14341434
if err != nil {
14351435
p.badWellknownMetadata.add(ErrorType,
1436-
fmt.Sprintf("Fetching %s failed: %v", path, err))
1436+
"Fetching %s failed: %v", path, err)
14371437
return
14381438
}
14391439
if res.StatusCode != http.StatusOK {
1440-
p.badWellknownMetadata.add(ErrorType, fmt.Sprintf("Fetching %s failed. Status code %d (%s)",
1441-
path, res.StatusCode, res.Status))
1440+
p.badWellknownMetadata.add(ErrorType, "Fetching %s failed. Status code %d (%s)",
1441+
path, res.StatusCode, res.Status)
14421442
}
14431443
}
14441444

@@ -1475,13 +1475,13 @@ func (p *processor) checkWellknownSecurityDNS(domain string) error {
14751475
// but found in the legacy location, and inform about finding it there (2).
14761476
switch warnings {
14771477
case 0:
1478-
p.badSecurity.add(InfoType, sDMessage)
1478+
p.badSecurity.add(InfoType, "%s", sDMessage)
14791479
case 1:
1480-
p.badSecurity.add(ErrorType, sDMessage)
1481-
p.badSecurity.add(ErrorType, sLMessage)
1480+
p.badSecurity.add(ErrorType, "%s", sDMessage)
1481+
p.badSecurity.add(ErrorType, "%s", sLMessage)
14821482
case 2:
1483-
p.badSecurity.add(WarnType, sDMessage)
1484-
p.badSecurity.add(InfoType, sLMessage)
1483+
p.badSecurity.add(WarnType, "%s", sDMessage)
1484+
p.badSecurity.add(InfoType, "%s", sLMessage)
14851485
}
14861486

14871487
p.checkDNS(domain)

internal/models/models_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestUnmarshalText(t *testing.T) {
8181
byteSlice := []byte{'3', 'h'}
8282
var emptySlice []byte
8383
if testTimeRange.UnmarshalText(byteSlice) != nil {
84-
t.Errorf(testTimeRange.UnmarshalText(byteSlice).Error())
84+
t.Error(testTimeRange.UnmarshalText(byteSlice).Error())
8585
}
8686
if testTimeRange.UnmarshalText(emptySlice) == nil {
8787
t.Errorf("Failure: UnmarshalText succeeded on invalid slice of bytes.")
@@ -104,10 +104,10 @@ func TestUnmarshalFlag(t *testing.T) {
104104
time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
105105
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC))
106106
if err := testTimeRange.UnmarshalFlag("3h"); err != nil {
107-
t.Errorf(err.Error())
107+
t.Error(err.Error())
108108
}
109109
if err := testTimeRange.UnmarshalFlag("2006-01-02T15:04:05"); err != nil {
110-
t.Errorf(err.Error())
110+
t.Error(err.Error())
111111
}
112112
if err := testTimeRange.UnmarshalFlag("2006-01-02T15:04:05a"); err == nil {
113113
t.Errorf("Failure: Extracted time from invalid string")
@@ -119,7 +119,7 @@ func TestUnmarshalFlag(t *testing.T) {
119119
t.Errorf("Failure: Extracted time from invalid string")
120120
}
121121
if err := testTimeRange.UnmarshalFlag("2006-01-02T15:04:05, 2007-01-02T15:04:05"); err != nil {
122-
t.Errorf(err.Error())
122+
t.Error(err.Error())
123123
}
124124
}
125125

internal/options/options_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestParse(t *testing.T) {
9090
cmd.Env = append(os.Environ(), "TEST_HELP=1")
9191
err := cmd.Run()
9292
if err != nil {
93-
t.Fatalf(err.Error())
93+
t.Fatal(err.Error())
9494
}
9595

9696
// test the version flag
@@ -104,7 +104,7 @@ func TestParse(t *testing.T) {
104104
cmd.Env = append(os.Environ(), "TEST_VERSION=1")
105105
err = cmd.Run()
106106
if err != nil {
107-
t.Fatalf(err.Error())
107+
t.Fatal(err.Error())
108108
}
109109
}
110110

@@ -140,7 +140,7 @@ func TestLoadToml(t *testing.T) {
140140
t.Errorf("Failure: Succeeded in parsing nonexistant parameter")
141141
}
142142
if err := loadTOML(&cfg, "data/config.toml"); err != nil {
143-
t.Errorf(err.Error())
143+
t.Error(err.Error())
144144
}
145145
}
146146

0 commit comments

Comments
 (0)