@@ -316,7 +316,7 @@ schema_diff_pnode_path(const struct lysp_node *node)
316316 path = ly_realloc (path , new_len + 1 );
317317 LY_CHECK_ERR_GOTO (!path , LOGMEM (NULL ), cleanup );
318318
319- sprintf (path + path_len , "/%s%s%s" , node_pre ? node_pre : "" , nodes [i ]-> name , node_post ? node_post : "" );
319+ snprintf (path + path_len , new_len + 1 - path_len , "/%s%s%s" , node_pre ? node_pre : "" , nodes [i ]-> name , node_post ? node_post : "" );
320320 path_len = new_len ;
321321 } while (i );
322322
@@ -491,11 +491,11 @@ schema_diff_ext_inst_substmts_bitenums(const struct ly_ctx *ctx, const struct ly
491491
492492 /* value/position */
493493 if (items [u ].flags & LYS_IS_ENUM ) {
494- sprintf ( num_str , "%" PRId32 , items [u ].value );
494+ snprintf ( num_str , sizeof num_str , "%" PRId32 , items [u ].value );
495495 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , "value" , num_str , & bitenum_node -> child ),
496496 cleanup );
497497 } else {
498- sprintf ( num_str , "%" PRIu32 , items [u ].position );
498+ snprintf ( num_str , sizeof num_str , "%" PRIu32 , items [u ].position );
499499 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , "position" , num_str , & bitenum_node -> child ),
500500 cleanup );
501501 }
@@ -611,16 +611,16 @@ schema_diff_range2str(struct lysc_range_part *parts, ly_bool is_signed, char **s
611611
612612 LYA_FOR (parts , u ) {
613613 if (is_signed ) {
614- sprintf ( num_min_str , "%" PRId64 , parts [u ].min_64 );
614+ snprintf ( num_min_str , sizeof num_min_str , "%" PRId64 , parts [u ].min_64 );
615615 if (parts [u ].min_64 < parts [u ].max_64 ) {
616- sprintf ( num_max_str , "%" PRId64 , parts [u ].max_64 );
616+ snprintf ( num_max_str , sizeof num_max_str , "%" PRId64 , parts [u ].max_64 );
617617 } else {
618618 num_max_str [0 ] = '\0' ;
619619 }
620620 } else {
621- sprintf ( num_min_str , "%" PRIu64 , parts [u ].min_u64 );
621+ snprintf ( num_min_str , sizeof num_min_str , "%" PRIu64 , parts [u ].min_u64 );
622622 if (parts [u ].min_u64 < parts [u ].max_u64 ) {
623- sprintf ( num_max_str , "%" PRIu64 , parts [u ].max_u64 );
623+ snprintf ( num_max_str , sizeof num_max_str , "%" PRIu64 , parts [u ].max_u64 );
624624 } else {
625625 num_max_str [0 ] = '\0' ;
626626 }
@@ -630,7 +630,7 @@ schema_diff_range2str(struct lysc_range_part *parts, ly_bool is_signed, char **s
630630 s = ly_realloc (s , new_len + 1 );
631631 LY_CHECK_ERR_GOTO (!s , LOGMEM (NULL ); rc = LY_EMEM , cleanup );
632632
633- sprintf (s + s_len , "%s%s%s%s" , s_len ? "|" : "" , num_min_str , num_max_str [0 ] ? ".." : "" ,
633+ snprintf (s + s_len , new_len + 1 - s_len , "%s%s%s%s" , s_len ? "|" : "" , num_min_str , num_max_str [0 ] ? ".." : "" ,
634634 num_max_str [0 ] ? num_max_str : "" );
635635 s_len = new_len ;
636636 }
@@ -877,7 +877,7 @@ schema_diff_ext_inst_substmts_type(const struct ly_ctx *ctx, const struct lysc_t
877877 type_dec = (const struct lysc_type_dec * )type ;
878878
879879 /* fraction-digits */
880- sprintf ( num_str , "%" PRIu8 , type_dec -> fraction_digits );
880+ snprintf ( num_str , sizeof num_str , "%" PRIu8 , type_dec -> fraction_digits );
881881 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , "fraction-digits" , num_str , child_p ), cleanup );
882882
883883 /* range */
@@ -1099,12 +1099,12 @@ schema_diff_ext_inst_substmts_nodes_r(const struct lysc_node *sibling, struct ly
10991099 max = llist -> max ;
11001100 }
11011101 if (min > 0 ) {
1102- sprintf ( num_str , "%" PRIu32 , min );
1102+ snprintf ( num_str , sizeof num_str , "%" PRIu32 , min );
11031103 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , "min-elements" , num_str , & node -> child ),
11041104 cleanup );
11051105 }
11061106 if (max < UINT32_MAX ) {
1107- sprintf ( num_str , "%" PRIu32 , max );
1107+ snprintf ( num_str , sizeof num_str , "%" PRIu32 , max );
11081108 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , "max-elements" , num_str , & node -> child ),
11091109 cleanup );
11101110 }
@@ -1221,7 +1221,7 @@ schema_diff_ext_inst_substmts(const struct ly_ctx *ctx, const struct lysc_ext_su
12211221
12221222 /* uint8 number */
12231223 if (* (substmts [u ].storage_p )) {
1224- sprintf ( num_str , "%" PRIu8 , * (uint8_t * )substmts [u ].storage_p );
1224+ snprintf ( num_str , sizeof num_str , "%" PRIu8 , * (uint8_t * )substmts [u ].storage_p );
12251225 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , lys_stmt_str (substmts [u ].stmt ), num_str ,
12261226 child_p ), cleanup );
12271227 }
@@ -1253,7 +1253,7 @@ schema_diff_ext_inst_substmts(const struct ly_ctx *ctx, const struct lysc_ext_su
12531253
12541254 /* uint32 number */
12551255 if (* (uint32_t * )substmts [u ].storage_p < UINT32_MAX ) {
1256- sprintf ( num_str , "%" PRIu32 , * (uint32_t * )substmts [u ].storage_p );
1256+ snprintf ( num_str , sizeof num_str , "%" PRIu32 , * (uint32_t * )substmts [u ].storage_p );
12571257 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , "max-elements" , num_str , child_p ),
12581258 cleanup );
12591259 }
@@ -1264,7 +1264,7 @@ schema_diff_ext_inst_substmts(const struct ly_ctx *ctx, const struct lysc_ext_su
12641264
12651265 /* uint32 number */
12661266 if (* (uint32_t * )substmts [u ].storage_p > 0 ) {
1267- sprintf ( num_str , "%" PRIu32 , * (uint32_t * )substmts [u ].storage_p );
1267+ snprintf ( num_str , sizeof num_str , "%" PRIu32 , * (uint32_t * )substmts [u ].storage_p );
12681268 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , "min-elements" , num_str , child_p ),
12691269 cleanup );
12701270 }
@@ -1290,7 +1290,7 @@ schema_diff_ext_inst_substmts(const struct ly_ctx *ctx, const struct lysc_ext_su
12901290 char num_str [21 ];
12911291
12921292 /* uint64 number */
1293- sprintf ( num_str , "%" PRIu64 , * (uint64_t * )substmts [u ].storage_p );
1293+ snprintf ( num_str , sizeof num_str , "%" PRIu64 , * (uint64_t * )substmts [u ].storage_p );
12941294 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , "position" , num_str , child_p ), cleanup );
12951295 break ;
12961296 }
@@ -1334,7 +1334,7 @@ schema_diff_ext_inst_substmts(const struct ly_ctx *ctx, const struct lysc_ext_su
13341334 char num_str [21 ];
13351335
13361336 /* int64 number */
1337- sprintf ( num_str , "%" PRId64 , * (int64_t * )substmts [u ].storage_p );
1337+ snprintf ( num_str , sizeof num_str , "%" PRId64 , * (int64_t * )substmts [u ].storage_p );
13381338 LY_CHECK_GOTO (rc = schema_diff_ext_inst_substmts_child_add (ctx , "value" , num_str , child_p ), cleanup );
13391339 break ;
13401340 }
@@ -1958,11 +1958,11 @@ schema_diff_parsed_enum(const struct lysp_type_enum *enm, ly_bool is_bit, struct
19581958
19591959 if (is_bit ) {
19601960 /* position */
1961- sprintf ( str , "%" PRIu64 , (uint64_t )enm -> value );
1961+ snprintf ( str , sizeof str , "%" PRIu64 , (uint64_t )enm -> value );
19621962 LY_CHECK_GOTO (rc = lyd_new_term (enum_list , NULL , "position" , str , LYD_NEW_VAL_CANON , NULL ), cleanup );
19631963 } else {
19641964 /* value */
1965- sprintf ( str , "%" PRId64 , enm -> value );
1965+ snprintf ( str , sizeof str , "%" PRId64 , enm -> value );
19661966 LY_CHECK_GOTO (rc = lyd_new_term (enum_list , NULL , "value" , str , LYD_NEW_VAL_CANON , NULL ), cleanup );
19671967 }
19681968
@@ -2011,7 +2011,7 @@ schema_diff_parsed_type(const struct lysp_type *type, struct lyd_node *cont)
20112011
20122012 /* fraction-digits */
20132013 if (type -> flags & LYS_SET_FRDIGITS ) {
2014- sprintf ( str , "%" PRIu8 , type -> fraction_digits );
2014+ snprintf ( str , sizeof str , "%" PRIu8 , type -> fraction_digits );
20152015 LY_CHECK_GOTO (rc = lyd_new_term (cont , NULL , "fraction-digits" , str , LYD_NEW_VAL_CANON , NULL ), cleanup );
20162016 }
20172017
@@ -2264,15 +2264,15 @@ schema_diff_pnode(const struct lysp_node *pnode, struct lyd_node *change_cont)
22642264
22652265 /* min-elements */
22662266 if (min_set ) {
2267- sprintf ( buf , "%" PRIu32 , min );
2267+ snprintf ( buf , sizeof buf , "%" PRIu32 , min );
22682268 if ((rc = lyd_new_term (change_cont , NULL , "min-elements" , buf , 0 , NULL ))) {
22692269 goto cleanup ;
22702270 }
22712271 }
22722272
22732273 /* max-elements */
22742274 if (max_set ) {
2275- sprintf ( buf , "%" PRIu32 , max );
2275+ snprintf ( buf , sizeof buf , "%" PRIu32 , max );
22762276 if ((rc = lyd_new_term (change_cont , NULL , "max-elements" , buf , 0 , NULL ))) {
22772277 goto cleanup ;
22782278 }
@@ -2405,15 +2405,15 @@ schema_diff_refine(const struct lysp_refine *refine, struct lyd_node *change_con
24052405
24062406 /* min-elements */
24072407 if (refine -> flags & LYS_SET_MIN ) {
2408- sprintf ( buf , "%" PRIu32 , refine -> min );
2408+ snprintf ( buf , sizeof buf , "%" PRIu32 , refine -> min );
24092409 if ((rc = lyd_new_term (change_cont , NULL , "min-elements" , buf , 0 , NULL ))) {
24102410 goto cleanup ;
24112411 }
24122412 }
24132413
24142414 /* max-elements */
24152415 if (refine -> flags & LYS_SET_MAX ) {
2416- sprintf ( buf , "%" PRIu32 , refine -> max );
2416+ snprintf ( buf , sizeof buf , "%" PRIu32 , refine -> max );
24172417 if ((rc = lyd_new_term (change_cont , NULL , "max-elements" , buf , 0 , NULL ))) {
24182418 goto cleanup ;
24192419 }
@@ -3122,15 +3122,15 @@ schema_diff_deviation(const struct lysp_deviation *dev, struct lyd_node *change_
31223122
31233123 /* min-elements */
31243124 if (flags & LYS_SET_MIN ) {
3125- sprintf ( buf , "%" PRIu32 , min );
3125+ snprintf ( buf , sizeof buf , "%" PRIu32 , min );
31263126 if ((rc = lyd_new_term (dev_list , NULL , "min-elements" , buf , 0 , NULL ))) {
31273127 goto cleanup ;
31283128 }
31293129 }
31303130
31313131 /* max-elements */
31323132 if (flags & LYS_SET_MAX ) {
3133- sprintf ( buf , "%" PRIu32 , max );
3133+ snprintf ( buf , sizeof buf , "%" PRIu32 , max );
31343134 if ((rc = lyd_new_term (dev_list , NULL , "max-elements" , buf , 0 , NULL ))) {
31353135 goto cleanup ;
31363136 }
@@ -3523,10 +3523,10 @@ schema_diff_node_type_bitenums(const struct lysc_type_bitenum_item *items, struc
35233523
35243524 /* value/position */
35253525 if (items [u ].flags & LYS_IS_ENUM ) {
3526- sprintf ( buf , "%" PRId32 , items [u ].value );
3526+ snprintf ( buf , sizeof buf , "%" PRId32 , items [u ].value );
35273527 LY_CHECK_GOTO (rc = lyd_new_term (par_list , NULL , "value" , buf , 0 , NULL ), cleanup );
35283528 } else {
3529- sprintf ( buf , "%" PRIu32 , items [u ].position );
3529+ snprintf ( buf , sizeof buf , "%" PRIu32 , items [u ].position );
35303530 LY_CHECK_GOTO (rc = lyd_new_term (par_list , NULL , "position" , buf , 0 , NULL ), cleanup );
35313531 }
35323532
@@ -3625,7 +3625,7 @@ schema_diff_node_type(const struct lysc_type *type, struct lyd_node *type_par)
36253625 type_dec = (const struct lysc_type_dec * )type ;
36263626
36273627 /* fraction-digits */
3628- sprintf ( buf , "%" PRIu8 , type_dec -> fraction_digits );
3628+ snprintf ( buf , sizeof buf , "%" PRIu8 , type_dec -> fraction_digits );
36293629 LY_CHECK_GOTO (rc = lyd_new_term (type_par , NULL , "fraction-digits" , buf , 0 , NULL ), cleanup );
36303630
36313631 /* range */
@@ -3828,13 +3828,13 @@ schema_diff_node_stmts(const struct lysc_node *node, ly_bool gen_local, struct l
38283828 max = llist -> max ;
38293829 }
38303830 if (min > 0 ) {
3831- sprintf ( buf , "%" PRIu32 , min );
3831+ snprintf ( buf , sizeof buf , "%" PRIu32 , min );
38323832 if ((rc = lyd_new_term (change_cont , NULL , "min-elements" , buf , 0 , NULL ))) {
38333833 goto cleanup ;
38343834 }
38353835 }
38363836 if (max < UINT32_MAX ) {
3837- sprintf ( buf , "%" PRIu32 , max );
3837+ snprintf ( buf , sizeof buf , "%" PRIu32 , max );
38383838 if ((rc = lyd_new_term (change_cont , NULL , "max-elements" , buf , 0 , NULL ))) {
38393839 goto cleanup ;
38403840 }
0 commit comments