Skip to content

Commit a27ede0

Browse files
committed
all: remove a few unused parameters
I recently modified tabwriter to reduce the number of defers due to flush calls. However, I forgot to notice that the new function flushNoDefers can no longer return an error, due to the lack of the defer. In crypto/tls, hashForServerKeyExchange never returned a non-nil error, so simplify the code. Finally, in go/types and net we can find a few trivially unused parameters, so remove them. Change-Id: I54c8de83fbc944df432453b55c93008d7e810e61 Reviewed-on: https://go-review.googlesource.com/c/go/+/174131 Run-TryBot: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Benny Siegert <[email protected]>
1 parent 45ed3db commit a27ede0

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

src/crypto/tls/key_agreement.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,19 @@ func md5SHA1Hash(slices [][]byte) []byte {
106106
// hashForServerKeyExchange hashes the given slices and returns their digest
107107
// using the given hash function (for >= TLS 1.2) or using a default based on
108108
// the sigType (for earlier TLS versions).
109-
func hashForServerKeyExchange(sigType uint8, hashFunc crypto.Hash, version uint16, slices ...[]byte) ([]byte, error) {
109+
func hashForServerKeyExchange(sigType uint8, hashFunc crypto.Hash, version uint16, slices ...[]byte) []byte {
110110
if version >= VersionTLS12 {
111111
h := hashFunc.New()
112112
for _, slice := range slices {
113113
h.Write(slice)
114114
}
115115
digest := h.Sum(nil)
116-
return digest, nil
116+
return digest
117117
}
118118
if sigType == signatureECDSA {
119-
return sha1Hash(slices), nil
119+
return sha1Hash(slices)
120120
}
121-
return md5SHA1Hash(slices), nil
121+
return md5SHA1Hash(slices)
122122
}
123123

124124
// ecdheKeyAgreement implements a TLS key agreement where the server
@@ -185,10 +185,7 @@ NextCandidate:
185185
return nil, errors.New("tls: certificate cannot be used with the selected cipher suite")
186186
}
187187

188-
digest, err := hashForServerKeyExchange(sigType, hashFunc, ka.version, clientHello.random, hello.random, serverECDHParams)
189-
if err != nil {
190-
return nil, err
191-
}
188+
digest := hashForServerKeyExchange(sigType, hashFunc, ka.version, clientHello.random, hello.random, serverECDHParams)
192189

193190
signOpts := crypto.SignerOpts(hashFunc)
194191
if sigType == signatureRSAPSS {
@@ -297,10 +294,7 @@ func (ka *ecdheKeyAgreement) processServerKeyExchange(config *Config, clientHell
297294
}
298295
sig = sig[2:]
299296

300-
digest, err := hashForServerKeyExchange(sigType, hashFunc, ka.version, clientHello.random, serverHello.random, serverECDHParams)
301-
if err != nil {
302-
return err
303-
}
297+
digest := hashForServerKeyExchange(sigType, hashFunc, ka.version, clientHello.random, serverHello.random, serverECDHParams)
304298
return verifyHandshakeSignature(sigType, cert.PublicKey, hashFunc, digest, sig)
305299
}
306300

src/go/types/call.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature,
241241
if i == n-1 && call.Ellipsis.IsValid() {
242242
ellipsis = call.Ellipsis
243243
}
244-
check.argument(call.Fun, sig, i, x, ellipsis, context)
244+
check.argument(sig, i, x, ellipsis, context)
245245
}
246246
}
247247

@@ -259,7 +259,7 @@ func (check *Checker) arguments(x *operand, call *ast.CallExpr, sig *Signature,
259259

260260
// argument checks passing of argument x to the i'th parameter of the given signature.
261261
// If ellipsis is valid, the argument is followed by ... at that position in the call.
262-
func (check *Checker) argument(fun ast.Expr, sig *Signature, i int, x *operand, ellipsis token.Pos, context string) {
262+
func (check *Checker) argument(sig *Signature, i int, x *operand, ellipsis token.Pos, context string) {
263263
check.singleValue(x)
264264
if x.mode == invalid {
265265
return

src/net/dnsclient_unix.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (r *Resolver) exchange(ctx context.Context, server string, q dnsmessage.Que
183183
}
184184

185185
// checkHeader performs basic sanity checks on the header.
186-
func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header, name, server string) error {
186+
func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header) error {
187187
if h.RCode == dnsmessage.RCodeNameError {
188188
return errNoSuchHost
189189
}
@@ -214,7 +214,7 @@ func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header, name, server string)
214214
return nil
215215
}
216216

217-
func skipToAnswer(p *dnsmessage.Parser, qtype dnsmessage.Type, name, server string) error {
217+
func skipToAnswer(p *dnsmessage.Parser, qtype dnsmessage.Type) error {
218218
for {
219219
h, err := p.AnswerHeader()
220220
if err == dnsmessage.ErrSectionDone {
@@ -272,7 +272,7 @@ func (r *Resolver) tryOneName(ctx context.Context, cfg *dnsConfig, name string,
272272
continue
273273
}
274274

275-
if err := checkHeader(&p, h, name, server); err != nil {
275+
if err := checkHeader(&p, h); err != nil {
276276
dnsErr := &DNSError{
277277
Err: err.Error(),
278278
Name: name,
@@ -292,7 +292,7 @@ func (r *Resolver) tryOneName(ctx context.Context, cfg *dnsConfig, name string,
292292
continue
293293
}
294294

295-
err = skipToAnswer(&p, qtype, name, server)
295+
err = skipToAnswer(&p, qtype)
296296
if err == nil {
297297
return p, server, nil
298298
}

src/text/tabwriter/tabwriter.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,14 @@ func (b *Writer) Flush() error {
499499
// don't want to expose.
500500
func (b *Writer) flush() (err error) {
501501
defer b.handlePanic(&err, "Flush")
502-
return b.flushNoDefers()
502+
b.flushNoDefers()
503+
return nil
503504
}
504505

505506
// flushNoDefers is like flush, but without a deferred handlePanic call. This
506507
// can be called from other methods which already have their own deferred
507508
// handlePanic calls, such as Write, and avoid the extra defer work.
508-
func (b *Writer) flushNoDefers() (err error) {
509+
func (b *Writer) flushNoDefers() {
509510
// add current cell if not empty
510511
if b.cell.size > 0 {
511512
if b.endChar != 0 {
@@ -518,7 +519,6 @@ func (b *Writer) flushNoDefers() (err error) {
518519
// format contents of buffer
519520
b.format(0, 0, len(b.lines))
520521
b.reset()
521-
return nil
522522
}
523523

524524
var hbar = []byte("---\n")
@@ -551,9 +551,7 @@ func (b *Writer) Write(buf []byte) (n int, err error) {
551551
// the formatting of the following lines (the last cell per
552552
// line is ignored by format()), thus we can flush the
553553
// Writer contents.
554-
if err = b.flushNoDefers(); err != nil {
555-
return
556-
}
554+
b.flushNoDefers()
557555
if ch == '\f' && b.flags&Debug != 0 {
558556
// indicate section break
559557
b.write0(hbar)

0 commit comments

Comments
 (0)