Commit 543121d8 authored by Loïck Bonniot's avatar Loïck Bonniot

Merge branch 'fix_open_contract_crash' into 'master'

[gui][c] Fix unmarshal when corrupted dfss json

Fix #10

See merge request !71
parents 87d3948f fcd05d6c
Pipeline #1184 passed with stages
...@@ -2,6 +2,7 @@ package common ...@@ -2,6 +2,7 @@ package common
import ( import (
"encoding/json" "encoding/json"
"errors"
"dfss/dfssp/contract" "dfss/dfssp/contract"
) )
...@@ -15,5 +16,9 @@ func UnmarshalDFSSFile(data []byte) (*contract.JSON, error) { ...@@ -15,5 +16,9 @@ func UnmarshalDFSSFile(data []byte) (*contract.JSON, error) {
return nil, err return nil, err
} }
if c.File == nil {
return nil, errors.New("empty file description")
}
return c, nil return c, nil
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
package showcontract package showcontract
import ( import (
"encoding/json"
"io/ioutil" "io/ioutil"
"dfss/dfssc/common"
"dfss/dfssp/contract" "dfss/dfssp/contract"
"github.com/visualfc/goqt/ui" "github.com/visualfc/goqt/ui"
) )
...@@ -49,8 +49,7 @@ func Load(filename string) *contract.JSON { ...@@ -49,8 +49,7 @@ func Load(filename string) *contract.JSON {
return nil return nil
} }
contract := new(contract.JSON) contract, err := common.UnmarshalDFSSFile(data)
err = json.Unmarshal(data, contract)
if err != nil { if err != nil {
return nil return nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment