slweb

Једноставни генератор статичких веб страна
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување c61b0874f7df9eadb7f7fee752becee1208e8beb
родитељ b65f5acbcbd7f3e340c564cdf5293d6355036fda
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Fri, 14 Jan 2022 00:28:40 +0100

Switch strncpy -> strcpy, strncat -> strcat

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
Mslweb.c | 246++++++++++++++++++++++++++++++-------------------------------------------------
измењених датотека: 1, додавања: 92(+), брисања: 154(-)

diff --git a/slweb.c b/slweb.c @@ -222,7 +222,7 @@ set_basedir(char** basedir, size_t* basedir_size, const char* arg) *basedir_size = arg_len + 1; REALLOC(*basedir, char, *basedir_size); } - strncpy(*basedir, arg, *basedir_size - 1); + strcpy(*basedir, arg); *(*basedir + arg_len) = 0; basedir_len = strlen(*basedir); if (*(*basedir + basedir_len - 1) == '/') @@ -245,7 +245,7 @@ set_global_link_prefix(char** global_link_prefix, *global_link_prefix_size = arg_len + 1; REALLOC(*global_link_prefix, char, *global_link_prefix_size); } - strncpy(*global_link_prefix, arg, *global_link_prefix_size - 1); + strcpy(*global_link_prefix, arg); *(*global_link_prefix + arg_len) = 0; return 0; @@ -293,8 +293,7 @@ print_output(FILE* output, const char* fmt, ...) { csv_template_size = BUFSIZE; CALLOC(csv_template, u8, csv_template_size); - strncpy((char*)csv_template, buf, BUFSIZE - 1); - *(csv_template + buf_len) = 0; + strcpy((char*)csv_template, buf); } else { @@ -304,9 +303,7 @@ print_output(FILE* output, const char* fmt, ...) csv_template_size += BUFSIZE; REALLOC(csv_template, u8, csv_template_size); } - strncat((char*)csv_template, buf, - csv_template_size - strlen((char*)csv_template) - - 1); + strcat((char*)csv_template, buf); } } else if (IN(state, ST_TSV_BODY)) @@ -318,8 +315,7 @@ print_output(FILE* output, const char* fmt, ...) { tsv_template_size = BUFSIZE; CALLOC(tsv_template, u8, tsv_template_size); - strncpy((char*)tsv_template, buf, BUFSIZE - 1); - *(tsv_template + buf_len) = 0; + strcpy((char*)tsv_template, buf); } else { @@ -329,9 +325,7 @@ print_output(FILE* output, const char* fmt, ...) tsv_template_size += BUFSIZE; REALLOC(tsv_template, u8, tsv_template_size); } - strncat((char*)tsv_template, buf, - tsv_template_size - strlen((char*)tsv_template) - - 1); + strcat((char*)tsv_template, buf); } } else @@ -533,9 +527,9 @@ process_git_log(FILE* output) pid_t result = 0; if (slash) - strncpy(basename, slash + 1, basename_size - 1); + strcpy(basename, slash + 1); else - strncpy(basename, input_filename, basename_size - 1); + strcpy(basename, input_filename); u8* pipe_args[] = {(u8*)basename, NULL}; @@ -820,12 +814,12 @@ read_tsv(FILE* output, const char* filename, tsv_callback_t callback) *ptoken = 0; if (tsv_lineno > 0 && current_register < MAX_TSV_REGISTERS) - strncpy((char*)tsv_register[current_register++], - (char*)token, BUFSIZE - 1); + strcpy((char*)tsv_register[current_register++], + (char*)token); else if (tsv_lineno <= 0 && current_header < MAX_TSV_REGISTERS) - strncpy((char*)tsv_header[current_header++], - (char*)token, BUFSIZE - 1); + strcpy((char*)tsv_header[current_header++], + (char*)token); RESET_TOKEN(token, ptoken, token_size); pbufline++; break; @@ -838,14 +832,14 @@ read_tsv(FILE* output, const char* filename, tsv_callback_t callback) if (tsv_lineno > 0) { if (current_register < MAX_TSV_REGISTERS) - strncpy((char*)tsv_register[current_register++], - (char*)token, BUFSIZE - 1); + strcpy((char*)tsv_register[current_register++], + (char*)token); } else { if (current_header < MAX_TSV_REGISTERS) - strncpy((char*)tsv_header[current_header++], - (char*)token, BUFSIZE - 1); + strcpy((char*)tsv_header[current_header++], + (char*)token); } RESET_TOKEN(token, ptoken, token_size); @@ -1150,13 +1144,13 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback) *ptoken = 0; if (csv_lineno > 0 && current_register < MAX_CSV_REGISTERS) - strncpy((char*)csv_register + strcpy((char*)csv_register [current_register++], - (char*)token, BUFSIZE - 1); + (char*)token); else if (csv_lineno <= 0 && current_header < MAX_CSV_REGISTERS) - strncpy((char*)csv_header[current_header++], - (char*)token, BUFSIZE - 1); + strcpy((char*)csv_header[current_header++], + (char*)token); RESET_TOKEN(token, ptoken, token_size); pbufline++; } @@ -1169,13 +1163,13 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback) *ptoken = 0; if (csv_lineno > 0 && current_register < MAX_CSV_REGISTERS) - strncpy((char*)csv_register + strcpy((char*)csv_register [current_register++], - (char*)token, BUFSIZE - 1); + (char*)token); else if (csv_lineno <= 0 && current_header < MAX_CSV_REGISTERS) - strncpy((char*)csv_header[current_header++], - (char*)token, BUFSIZE - 1); + strcpy((char*)csv_header[current_header++], + (char*)token); RESET_TOKEN(token, ptoken, token_size); pbufline++; } @@ -1188,14 +1182,14 @@ read_csv(FILE* output, const char* filename, csv_callback_t callback) if (csv_lineno > 0) { if (current_register < MAX_CSV_REGISTERS) - strncpy((char*)csv_register[current_register++], - (char*)token, BUFSIZE - 1); + strcpy((char*)csv_register[current_register++], + (char*)token); } else { if (current_header < MAX_CSV_REGISTERS) - strncpy((char*)csv_header[current_header++], - (char*)token, BUFSIZE - 1); + strcpy((char*)csv_header[current_header++], + (char*)token); } RESET_TOKEN(token, ptoken, token_size); @@ -1789,14 +1783,11 @@ process_timestamp(FILE* output, const u8* link_prefix, const char* link, while (*ptimestamp_format) { if (*ptimestamp_format == 'd' || *ptimestamp_format == 'D') - strncat((char*)formatted_date, (char*)day, - DATEBUFSIZE - strlen((char*)formatted_date) - 1); + strcat((char*)formatted_date, (char*)day); else if (*ptimestamp_format == 'm' || *ptimestamp_format == 'M') - strncat((char*)formatted_date, (char*)month, - DATEBUFSIZE - strlen((char*)formatted_date) - 1); + strcat((char*)formatted_date, (char*)month); else if (*ptimestamp_format == 'y' || *ptimestamp_format == 'Y') - strncat((char*)formatted_date, (char*)year, - DATEBUFSIZE - strlen((char*)formatted_date) - 1); + strcat((char*)formatted_date, (char*)year); else *(formatted_date + strlen((char*)formatted_date)) = *ptimestamp_format; @@ -1879,8 +1870,7 @@ process_macro(FILE* output, const u8* token, } CALLOC(pmacros->key, u8, KEYSIZE); pmacros->seen = FALSE; - strncpy((char*)pmacros->key, (char*)token + 1, - KEYSIZE - 1); + strcpy((char*)pmacros->key, (char*)token + 1); pmacros->value = NULL; pmacros->value_size = 0; } @@ -2253,7 +2243,7 @@ process_line_start(FILE* output, const u8* line, const u8* link_prefix, if (!read_yaml_macros_and_links && (IN(state, ST_PARA_OPEN))) { - print_output(output, "</p>\n"); + print_output(output, "@</p>\n"); output_firstcol = TRUE; } state &= ~(ST_FOOTNOTE_TEXT | ST_PARA_OPEN); @@ -2329,8 +2319,8 @@ process_inline_footnote(const u8* token, const BOOL read_yaml_macros_and_links, CALLOC(inline_footnotes[inline_footnote_count - 1], u8, token_len + 1); - strncpy((char*)inline_footnotes[inline_footnote_count - 1], - (char*)token, token_len + 1); + strcpy((char*)inline_footnotes[inline_footnote_count - 1], + (char*)token); *(inline_footnotes[inline_footnote_count - 1] + token_len) = 0; } else @@ -2370,7 +2360,7 @@ process_footnote(FILE* output, const u8* token, const BOOL footnote_definition, pfootnotes = footnotes + footnote_count - 1; } CALLOC(pfootnotes->key, u8, KEYSIZE); - strncpy((char*)pfootnotes->key, (char*)token, KEYSIZE - 1); + strcpy((char*)pfootnotes->key, (char*)token); pfootnotes->value = NULL; pfootnotes->value_size = 0; } @@ -2541,8 +2531,7 @@ begin_article(FILE* output, const char* source_filename, const u8* link_prefix, CALLOC(real_link, char, BUFSIZE); if (ext_in_permalink) - strncat(link, timestamp_output_ext, - BUFSIZE - strlen(link) - 1); + strcat(link, timestamp_output_ext); if (permalink_url) process_timestamp(output, link_prefix, permalink_url, @@ -2570,7 +2559,7 @@ end_footnotes(FILE* output, BOOL add_footnote_div) if (IN(state, ST_PARA_OPEN)) { - print_output(output, "</p>\n"); + print_output(output, "!!</p>\n"); output_firstcol = TRUE; state &= ~ST_PARA_OPEN; } @@ -2587,7 +2576,8 @@ end_footnotes(FILE* output, BOOL add_footnote_div) { print_output(output, "<p id=\"inline-footnote-%d\">" - "<a href=\"#inline-footnote-text-%d\">%d.</a> %s</p>\n", + "<a href=\"#inline-footnote-text-%d\">%d.</a> " + "%s?!?</p>\n", footnote + 1, footnote + 1, footnote + 1, (char*)inline_footnotes[footnote]); output_firstcol = TRUE; @@ -2599,7 +2589,7 @@ end_footnotes(FILE* output, BOOL add_footnote_div) { print_output(output, "<p id=\"footnote-%d\">" - "<a href=\"#footnote-text-%d\">%d.</a> %s</p>\n", + "<a href=\"#footnote-text-%d\">%d.</a> %s###</p>\n", footnote + 1, footnote + 1, footnote + 1, (char*)pfootnote->value); output_firstcol = TRUE; @@ -2692,12 +2682,10 @@ simple_parse_yaml_line(const u8* line, KeyValue** vars, size_t* vars_count, *pvars = *vars + *vars_count - 1; } CALLOC((*pvars)->key, u8, KEYSIZE); - strncpy((char*)(*pvars)->key, (char*)var_key, - KEYSIZE - 1); + strcpy((char*)(*pvars)->key, (char*)var_key); (*pvars)->value_size = strlen((char*)token) + 1; CALLOC((*pvars)->value, u8, (*pvars)->value_size); - strncpy((char*)(*pvars)->value, (char*)token, - (*pvars)->value_size); + strcpy((char*)(*pvars)->value, (char*)token); } } free(var_key); @@ -2915,7 +2903,7 @@ do_line: pvars = vars + vars_count - 1; } CALLOC(pvars->key, u8, KEYSIZE); - strncpy((char*)pvars->key, (char*)token, KEYSIZE - 1); + strcpy((char*)pvars->key, (char*)token); pvars->value = NULL; pvars->value_size = 0; @@ -2967,8 +2955,7 @@ do_line: if (token_len + entity_len < BUFSIZE) { - strncat((char*)token, (char*)entity, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)entity); ptoken += entity_len; } } @@ -3008,8 +2995,7 @@ do_line: if (token_len + entity_len < BUFSIZE) { - strncat((char*)token, (char*)entity, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)entity); ptoken += entity_len; } } @@ -3050,8 +3036,7 @@ do_line: if (token_len + tag_len < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } } @@ -3123,8 +3108,7 @@ do_line: if (token_len + tag_len < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } } @@ -3230,8 +3214,7 @@ do_line: if (token_len + tag_len < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } } @@ -3273,8 +3256,7 @@ do_line: if (token_len + tag_len < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } } @@ -3426,8 +3408,7 @@ do_line: if (token_len + tag_len < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } } @@ -3470,8 +3451,7 @@ do_line: if (token_len + tag_len < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } } @@ -3543,10 +3523,10 @@ do_line: if (strlen((char*)pline) == 2 && *(pline + 1) == ' ') { - *ptoken = 0; - strncat((char*)ptoken, "<br />", - BUFSIZE - strlen((char*)token) - 1); - ptoken += strlen("<br />"); + size_t br_len = strlen("<br />"); + *ptoken = 0; + strcat((char*)ptoken, "<br />"); + ptoken += br_len; output_firstcol = FALSE; pline++; colno++; @@ -3554,7 +3534,7 @@ do_line: else if (IN(state, ST_LINK_MACRO)) { *ptoken = 0; - strncpy((char*)link_macro, (char*)token, BUFSIZE - 1); + strcpy((char*)link_macro, (char*)token); *(link_macro + strlen((char*)token)) = 0; RESET_TOKEN(token, ptoken, token_size); state &= ~ST_LINK_MACRO; @@ -3602,18 +3582,16 @@ do_line: REALLOC(pmacros->value, u8, pmacros->value_size); } - strncat((char*)pmacros->value, - (char*)token, - pmacros->value_size - 1); + strcat((char*)pmacros->value, + (char*)token); } else { pmacros->value_size = token_len + 1; CALLOC(pmacros->value, u8, pmacros->value_size); - strncpy((char*)pmacros->value, - (char*)token, - pmacros->value_size - 1); + strcpy((char*)pmacros->value, + (char*)token); } } } @@ -3711,8 +3689,7 @@ do_line: if (token_len + tag_len < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } } @@ -3911,8 +3888,7 @@ do_line: { size_t lt_len = strlen("&lt;"); *ptoken = 0; - strncat((char*)token, "&lt;", - BUFSIZE - (ptoken - token) - 1); + strcat((char*)token, "&lt;"); ptoken += lt_len; pline++; colno++; @@ -4097,8 +4073,7 @@ do_line: if (token_len + tag_len < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } @@ -4127,8 +4102,7 @@ do_line: if (token_len + tag_len < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } @@ -4164,8 +4138,7 @@ do_line: if (token_len + tag_len + 1 < BUFSIZE) { - strncat((char*)token, (char*)tag, - BUFSIZE - token_len - 1); + strcat((char*)token, (char*)tag); ptoken += tag_len; } state &= ~ST_LINK_SPAN; @@ -4293,8 +4266,7 @@ do_line: plinks = links + links_count - 1; } CALLOC(plinks->key, u8, KEYSIZE); - strncpy((char*)plinks->key, (char*)token, - KEYSIZE - 1); + strcpy((char*)plinks->key, (char*)token); plinks->value = NULL; plinks->value_size = 0; pline += 2; @@ -4323,8 +4295,7 @@ do_line: link_size = token_len + 1; CALLOC(link_text, u8, link_size); } - strncpy((char*)link_text, (char*)token, - link_size - 1); + strcpy((char*)link_text, (char*)token); *(link_text + token_len) = 0; pline += 2; colno += 2; @@ -4554,8 +4525,7 @@ do_line: { size_t quot_len = strlen("&quot;"); *ptoken = 0; - strncat((char*)token, "&quot;", - BUFSIZE - (ptoken - token) - 1); + strcat((char*)token, "&quot;"); ptoken += quot_len; pline++; } @@ -4571,8 +4541,7 @@ do_line: { size_t quot_len = strlen("&amp;"); *ptoken = 0; - strncat((char*)token, "&amp;", - BUFSIZE - (ptoken - token) - 1); + strcat((char*)token, "&amp;"); ptoken += quot_len; pline++; } @@ -4602,12 +4571,10 @@ done_line: } pvars->value_size = strlen((char*)token) + 1; CALLOC(pvars->value, u8, pvars->value_size); - strncpy((char*)pvars->value, (char*)token, pvars->value_size); + strcpy((char*)pvars->value, (char*)token); } else if (keep_token) { - size_t token_len = strlen((char*)token); - if (ptoken + 2 > token + token_size) { size_t old_size = token_size; @@ -4615,9 +4582,8 @@ done_line: REALLOC(token, u8, token_size); ptoken = token + old_size - 1; } - strncat((char*)token, - ANY(state, ST_IMAGE | ST_LINK) ? " " : "\n", - token_size - token_len - 1); + strcat((char*)token, + ANY(state, ST_IMAGE | ST_LINK) ? " " : "\n"); ptoken++; *ptoken = 0; } @@ -4650,29 +4616,18 @@ done_line: REALLOC(pmacros->value, u8, pmacros->value_size); } - strncat((char*)pmacros->value, - (char*)token, - pmacros->value_size - value_len - - 1); - strncat((char*)pmacros->value, "\n", - pmacros->value_size - - strlen((char*)pmacros - ->value) - - 1); + strcat((char*)pmacros->value, + (char*)token); + strcat((char*)pmacros->value, "\n"); } else { pmacros->value_size = BUFSIZE; CALLOC(pmacros->value, u8, pmacros->value_size); - strncpy((char*)pmacros->value, - (char*)token, - pmacros->value_size - 1); - strncat((char*)pmacros->value, "\n", - pmacros->value_size - - strlen((char*)pmacros - ->value) - - 1); + strcpy((char*)pmacros->value, + (char*)token); + strcat((char*)pmacros->value, "\n"); } skip_macro_read:; } @@ -4701,31 +4656,18 @@ done_line: REALLOC(pfootnotes->value, u8, pfootnotes->value_size); } - strncat((char*)pfootnotes->value, - (char*)token, - pfootnotes->value_size - - value_len - 1); - strncat((char*)pfootnotes->value, "\n", - pfootnotes->value_size - - strlen( - (char*)pfootnotes - ->value) - - 1); + strcat((char*)pfootnotes->value, + (char*)token); + strcat((char*)pfootnotes->value, "\n"); } else { pfootnotes->value_size = BUFSIZE; CALLOC(pfootnotes->value, u8, pfootnotes->value_size); - strncpy((char*)pfootnotes->value, - (char*)token, - pfootnotes->value_size - 1); - strncat((char*)pfootnotes->value, "\n", - pfootnotes->value_size - - strlen( - (char*)pfootnotes - ->value) - - 1); + strcpy((char*)pfootnotes->value, + (char*)token); + strcat((char*)pfootnotes->value, "\n"); } skip_footnote_read:; } @@ -4746,9 +4688,8 @@ done_line: = strlen((char*)token) + 1; CALLOC(plinks->value, u8, plinks->value_size); - strncpy((char*)plinks->value, - (char*)token, - plinks->value_size - 1); + strcpy((char*)plinks->value, + (char*)token); } } else if (IN(state, ST_HEADING)) @@ -4842,18 +4783,16 @@ done_line: REALLOC(pfootnotes->value, u8, pfootnotes->value_size); } - strncat((char*)pfootnotes->value, - (char*)token, - pfootnotes->value_size - 1); + strcat((char*)pfootnotes->value, + (char*)token); } else { pfootnotes->value_size = token_len + 1; CALLOC(pfootnotes->value, u8, pfootnotes->value_size); - strncpy((char*)pfootnotes->value, - (char*)token, - pfootnotes->value_size); + strcpy((char*)pfootnotes->value, + (char*)token); } skip_footnote_text_read:; } @@ -5085,8 +5024,7 @@ main(const int argc, const char** argv) buffer_size += BUFSIZE; REALLOC(buffer, u8, buffer_size); } - strncat((char*)buffer, (char*)bufline, - buffer_size - buffer_len - 1); + strcat((char*)buffer, (char*)bufline); buffer_len += bufline_len; } free(bufline);