@@ -4139,49 +4139,82 @@ lys_compile_uses(struct lysc_ctx *ctx, struct lysp_node_uses *uses_p, struct lys
4139
4139
return rc ;
4140
4140
}
4141
4141
4142
+ /**
4143
+ * @brief Generate path of a grouping for logging.
4144
+ *
4145
+ * @param[in] ctx Compile context.
4146
+ * @param[in] node Grouping node.
4147
+ * @param[out] path Generated path.
4148
+ * @return Length of the generated @p path;
4149
+ * @return -1 on error.
4150
+ */
4142
4151
static int
4143
4152
lys_compile_grouping_pathlog (struct lysc_ctx * ctx , struct lysp_node * node , char * * path )
4144
4153
{
4145
4154
struct lysp_node * iter ;
4146
- int len = 0 ;
4155
+ int len = 0 , r ;
4156
+ char * s , * id ;
4147
4157
4148
4158
* path = NULL ;
4149
- for (iter = node ; iter && len >= 0 ; iter = iter -> parent ) {
4150
- char * s = * path ;
4151
- char * id ;
4152
4159
4160
+ for (iter = node ; iter && (len >= 0 ); iter = iter -> parent ) {
4161
+ s = * path ;
4162
+
4163
+ /* next node segment */
4153
4164
switch (iter -> nodetype ) {
4154
4165
case LYS_USES :
4155
- LY_CHECK_RET ( asprintf (& id , "{uses='%s'}" , iter -> name ) == -1 , -1 );
4166
+ r = asprintf (& id , "{uses='%s'}" , iter -> name );
4156
4167
break ;
4157
4168
case LYS_GROUPING :
4158
- LY_CHECK_RET ( asprintf (& id , "{grouping='%s'}" , iter -> name ) == -1 , -1 );
4169
+ r = asprintf (& id , "{grouping='%s'}" , iter -> name );
4159
4170
break ;
4160
4171
case LYS_AUGMENT :
4161
- LY_CHECK_RET ( asprintf (& id , "{augment='%s'}" , iter -> name ) == -1 , -1 );
4172
+ r = asprintf (& id , "{augment='%s'}" , iter -> name );
4162
4173
break ;
4163
4174
default :
4164
4175
id = strdup (iter -> name );
4176
+ r = id ? 1 : -1 ;
4165
4177
break ;
4166
4178
}
4179
+ if (r == -1 ) {
4180
+ len = -1 ;
4181
+ goto cleanup ;
4182
+ }
4167
4183
4184
+ /* append the segment to the path */
4168
4185
if (!iter -> parent ) {
4169
4186
/* print prefix */
4170
- len = asprintf (path , "/%s:%s%s" , ctx -> cur_mod -> name , id , s ? s : "" );
4187
+ r = asprintf (path , "/%s:%s%s" , ctx -> cur_mod -> name , id , s ? s : "" );
4171
4188
} else {
4172
4189
/* prefix is the same as in parent */
4173
- len = asprintf (path , "/%s%s" , id , s ? s : "" );
4190
+ r = asprintf (path , "/%s%s" , id , s ? s : "" );
4174
4191
}
4175
4192
free (s );
4176
4193
free (id );
4194
+ if (r == -1 ) {
4195
+ len = -1 ;
4196
+ goto cleanup ;
4197
+ }
4198
+
4199
+ /* remember the length of the full path */
4200
+ len = r ;
4177
4201
}
4178
4202
4203
+ if (!len ) {
4204
+ /* root node path */
4205
+ * path = strdup ("/" );
4206
+ if (!* path ) {
4207
+ len = -1 ;
4208
+ goto cleanup ;
4209
+ }
4210
+
4211
+ len = 1 ;
4212
+ }
4213
+
4214
+ cleanup :
4179
4215
if (len < 0 ) {
4180
4216
free (* path );
4181
4217
* path = NULL ;
4182
- } else if (len == 0 ) {
4183
- * path = strdup ("/" );
4184
- len = 1 ;
4185
4218
}
4186
4219
return len ;
4187
4220
}
0 commit comments