@@ -69,22 +69,29 @@ func checkSize(buildProperties properties.Map, verbose bool, warningsLevel strin
69
69
return nil
70
70
}
71
71
72
- maxTextSize , _ := strconv .Atoi (maxTextSizeString )
72
+ maxTextSize , err := strconv .Atoi (maxTextSizeString )
73
+ if err != nil {
74
+ return err
75
+ }
73
76
maxDataSize := - 1
74
77
75
78
if maxDataSizeString != "" {
76
- maxDataSize , _ = strconv .Atoi (maxDataSizeString )
79
+ maxDataSize , err = strconv .Atoi (maxDataSizeString )
80
+ if err != nil {
81
+ return err
82
+ }
77
83
}
78
84
79
- var textSize , dataSize , eepromSize int
85
+ textSize , dataSize , eepromSize := - 1 , - 1 , - 1
80
86
81
- err : = execSizeReceipe (properties , logger , & textSize , & dataSize , & eepromSize )
87
+ err = execSizeReceipe (properties , logger , & textSize , & dataSize , & eepromSize )
82
88
if err != nil {
83
- return err
89
+ logger .Println (constants .LOG_LEVEL_WARN , constants .MSG_SIZER_ERROR_NO_RULE )
90
+ return nil
84
91
}
85
92
86
93
logger .Println (constants .LOG_LEVEL_INFO , constants .MSG_SIZER_TEXT_FULL , strconv .Itoa (textSize ), strconv .Itoa (maxTextSize ), strconv .Itoa (textSize * 100 / maxTextSize ))
87
- if dataSize > 0 {
94
+ if dataSize >= 0 {
88
95
if maxDataSize > 0 {
89
96
logger .Println (constants .LOG_LEVEL_INFO , constants .MSG_SIZER_DATA_FULL , strconv .Itoa (dataSize ), strconv .Itoa (maxDataSize ), strconv .Itoa (dataSize * 100 / maxDataSize ), strconv .Itoa (maxDataSize - dataSize ))
90
97
} else {
@@ -103,7 +110,10 @@ func checkSize(buildProperties properties.Map, verbose bool, warningsLevel strin
103
110
}
104
111
105
112
if properties [constants .PROPERTY_WARN_DATA_PERCENT ] != "" {
106
- warnDataPercentage , _ := strconv .Atoi (properties [constants .PROPERTY_WARN_DATA_PERCENT ])
113
+ warnDataPercentage , err := strconv .Atoi (properties [constants .PROPERTY_WARN_DATA_PERCENT ])
114
+ if err != nil {
115
+ return err
116
+ }
107
117
if maxDataSize > 0 && dataSize > maxDataSize * warnDataPercentage / 100 {
108
118
logger .Println (constants .LOG_LEVEL_WARN , constants .MSG_SIZER_LOW_MEMORY )
109
119
}
@@ -117,25 +127,33 @@ func execSizeReceipe(properties properties.Map, logger i18n.Logger, textSize *in
117
127
out , err := builder_utils .ExecRecipe (properties , constants .RECIPE_SIZE_PATTERN , false , false , false , logger )
118
128
119
129
if err != nil {
120
- i18n .ErrorfWithLogger (logger , constants .MSG_SIZER_ERROR_NO_RULE )
121
130
return errors .New ("" )
122
131
}
123
132
124
133
// force multiline match prepending "(?m)" to the actual regexp
134
+ // return an error if RECIPE_SIZE_REGEXP doesn't exist
125
135
126
136
if len (properties [constants .RECIPE_SIZE_REGEXP ]) > 0 {
127
- textRegexp := regexp .MustCompile ("(?m)" + properties [constants .RECIPE_SIZE_REGEXP ])
137
+ textRegexp , err := regexp .Compile ("(?m)" + properties [constants .RECIPE_SIZE_REGEXP ])
138
+ if err != nil {
139
+ return errors .New ("" )
140
+ }
128
141
result := textRegexp .FindAllSubmatch (out , - 1 )
129
142
for _ , b := range result {
130
143
for _ , c := range b {
131
144
res , _ := strconv .Atoi (string (c ))
132
145
* textSize += res
133
146
}
134
147
}
148
+ } else {
149
+ return errors .New ("" )
135
150
}
136
151
137
152
if len (properties [constants .RECIPE_SIZE_REGEXP_DATA ]) > 0 {
138
- dataRegexp := regexp .MustCompile ("(?m)" + properties [constants .RECIPE_SIZE_REGEXP_DATA ])
153
+ dataRegexp , err := regexp .Compile ("(?m)" + properties [constants .RECIPE_SIZE_REGEXP_DATA ])
154
+ if err != nil {
155
+ return errors .New ("" )
156
+ }
139
157
result := dataRegexp .FindAllSubmatch (out , - 1 )
140
158
for _ , b := range result {
141
159
for _ , c := range b {
@@ -146,7 +164,10 @@ func execSizeReceipe(properties properties.Map, logger i18n.Logger, textSize *in
146
164
}
147
165
148
166
if len (properties [constants .RECIPE_SIZE_REGEXP_EEPROM ]) > 0 {
149
- eepromRegexp := regexp .MustCompile ("(?m)" + properties [constants .RECIPE_SIZE_REGEXP_EEPROM ])
167
+ eepromRegexp , err := regexp .Compile ("(?m)" + properties [constants .RECIPE_SIZE_REGEXP_EEPROM ])
168
+ if err != nil {
169
+ return errors .New ("" )
170
+ }
150
171
result := eepromRegexp .FindAllSubmatch (out , - 1 )
151
172
for _ , b := range result {
152
173
for _ , c := range b {
0 commit comments