Open cheesecrust opened 3 months ago
κΈ°μ‘΄μ μ½λλ #ifdef, #endif λ‘ λ¨κ²¨λμμ΅λλ€.
κΈ°μ‘΄ μ½λλ₯Ό λ¨κ²¨λλ μ΄μ λ λκ°μ?
λ°λΌμ ν¨μ νΈμΆ μ κ°μ§ μ μλ μ΅μ₯ κΈΈμ΄ λ§νΌμ λ©λͺ¨λ¦¬μ ν λΉνκ³
write_and_free
λ₯Ό μ¬μ©νμμ΅λλ€.μλΉν ν° λ©λͺ¨λ¦¬λ₯Ό ν λΉνκ³ ν΄μ νκ² λλλ°, μκ°ν΄ λ³Έ λ€λ₯Έ ꡬν λ°©μμ΄ μλμ?
λ°©μμ λ°κΎΈμ΄μ λ¨Όμ μΆλ ₯ν λ¬Έμμ΄μ κΈΈμ΄λ₯Ό μ° λ€μμ κ·Έμ λ§κ² ν λΉνλ λ°©μμΌλ‘ ꡬνμ λ°κΎΈμμ΅λλ€.
nxt += snprintf(nxt, bytes, "%s : %u\n", command_str[i], ldb.ntotal); bytes -= (nxt - result.value); if (ldb.ntotal != 0) { int length = bytes < ldb.offset ? bytes : ldb.offset; nxt += snprintf(nxt, length, "%s", ldb.data); bytes -= length;
nxt += snprintf(nxt, bytes - (nxt - result.value), "%s : %u\n", command_str[i], ldb.ntotal); if (ldb.ntotal != 0) { nxt += snprintf(nxt, ldb.offset + 1, "%s", ldb.data); } }
μλ ννμ ꡬνμ κ²ν ν΄ μ£ΌκΈ° λ°λλλ€.
int main(int argc, char **argv) {
int buflen = 200;
char *buf = (char*)malloc(buflen);
if (!buf) {
return 1;
}
int offset = 0;
int i;
for (i=0; i<20; i++) {
offset += snprintf(buf + offset, buflen - offset, "%d,", i);
//if (offset >= buflen) {
// break;
//}
}
printf("%s\n", buf);
free(buf);
return 0;
}
μλ ννμ ꡬνμ κ²ν ν΄ μ£ΌκΈ° λ°λλλ€.
int main(int argc, char **argv) { int buflen = 200; char *buf = (char*)malloc(buflen); if (!buf) { return 1; } int offset = 0; int i; for (i=0; i<20; i++) { offset += snprintf(buf + offset, buflen - offset, "%d,", i); //if (offset >= buflen) { // break; //} } printf("%s\n", buf); free(buf); return 0; }
μλ₯Ό κ²ν νμ¬ μλμ κ°μ΄ λ³κ²½νμμ΅λλ€.
if (result.value != NULL) { int offset = 0; for (int i = 0; i < LQ_CMD_NUM; i++) { struct lq_detect_buffer ldb = lqdetect.buffer[i]; offset += snprintf(result.value + offset, bytes - offset, "%s : %u\n", command_str[i], ldb.ntotal); if (ldb.ntotal != 0) { offset += snprintf(result.value + offset, ldb.offset + 1, "%s", ldb.data); } } result.length = offset; }
π Related Issue
β¨οΈ What I did
<value, length>
ꡬ쑰μ λ°°μ΄μ 리ν΄νλ λ‘μ§μμ κ°λ¨νκ²filed_t
νλλ§μ λ°ννλ λ‘μ§μΌλ‘ λ³κ²½νμμ΅λλ€.total_offset
μ μ μΈνμ¬ buffer μ offset μ΄ μ¦κ°ν λ κ°μ΄ μ¦κ°νμ¬ μ΄λ₯Ό νμ©νμ΅λλ€.SERVER ERROR out of memory writing show response.
λ₯Ό μΆλ ₯νλλ‘ νμμ΅λλ€.