Skip to content

Commit 87a396f

Browse files
glisten to validation configuration, fix uint conversion
# Conflicts: # pkg/datastore/transaction_rpc.go # pkg/server/datastore.go
1 parent cd6abb7 commit 87a396f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

pkg/server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ func (s *Server) createInitialDatastores(ctx context.Context) {
275275

276276
for _, dsCfg := range s.config.Datastores {
277277
log.Debugf("creating datastore %s", dsCfg.Name)
278+
dsCfg.Validation = s.config.Validation
278279
go func(dsCfg *config.DatastoreConfig) {
279280
defer wg.Done()
280281
// TODO: handle error

pkg/utils/leaf_convert.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,26 @@ func ConvertSdcpbNumberToUint64(mm *sdcpb.Number) (uint64, error) {
140140
return mm.Value, nil
141141
}
142142

143-
func ConvertSdcpbNumberToInt64(mm *sdcpb.Number) (int64, error) {
144-
if mm.Value > math.MaxInt64 {
145-
return 0, fmt.Errorf("error converting %d to int64 overflow", mm.Value)
143+
func intAbs(x int64) uint64 {
144+
ui := uint64(x)
145+
if x < 0 {
146+
return ^(ui) + 1
146147
}
148+
return ui
149+
}
147150

151+
func ConvertSdcpbNumberToInt64(mm *sdcpb.Number) (int64, error) {
148152
if mm.Negative {
153+
if mm.Value > intAbs(math.MinInt64) {
154+
return 0, fmt.Errorf("error converting -%d to int64: overflow", mm.Value)
155+
}
149156
return -int64(mm.Value), nil
150-
} else {
151-
return int64(mm.Value), nil
152157
}
158+
159+
if mm.Value > math.MaxInt64 {
160+
return 0, fmt.Errorf("error converting %d to int64 overflow", mm.Value)
161+
}
162+
return int64(mm.Value), nil
153163
}
154164

155165
func convertUint(value string, minMaxs []*sdcpb.SchemaMinMaxType, ranges *URnges) (*sdcpb.TypedValue, error) {

0 commit comments

Comments
 (0)