Skip to content

Commit

Permalink
Fix nil pointer dereference error (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
harryzcy authored Jul 17, 2022
1 parent 2f0b184 commit 04368dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/emails/list/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (apiutil.R
order := req.QueryStringParameters["order"]
nextCursor := req.QueryStringParameters["nextCursor"]

var cursor email.Cursor
var cursor *email.Cursor
err = cursor.BindString(nextCursor)
if err != nil {
return apiutil.NewErrorResponse(http.StatusBadRequest, "invalid input"), nil
Expand All @@ -51,7 +51,7 @@ func handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (apiutil.R
Year: year,
Month: month,
Order: order,
NextCursor: &cursor,
NextCursor: cursor,
})
if err != nil {
if err == email.ErrInvalidInput {
Expand Down
3 changes: 3 additions & 0 deletions internal/email/list_cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ func (c *Cursor) Bind(data []byte) error {
if len(data) == 0 {
return nil
}
if c == nil {
c = &Cursor{}
}

dst, err := decodeBase64Encoding(data)
if err != nil {
Expand Down

0 comments on commit 04368dc

Please sign in to comment.