{"record":{"id":"12031f718ac27631","repo":"DrKLO/Telegram","slug":"error-writing-n","errorCode":null,"errorMessage":"Error writing.\\n","messagePattern":"Error writing\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/src/repacketizer_demo.c","lineNumber":165,"sourceCode":"         if (err!=OPUS_OK)\n         {\n            fprintf(stderr, \"opus_repacketizer_cat() failed: %s\\n\", opus_strerror(err));\n            break;\n         }\n      }\n      nb_packets = i;\n\n      if (eof)\n         break;\n\n      if (!split)\n      {\n         err = opus_repacketizer_out(rp, output_packet, MAX_PACKETOUT);\n         if (err>0) {\n            unsigned char int_field[4];\n            int_to_char(err, int_field);\n            if(fwrite(int_field, 1, 4, fout)!=4){\n               fprintf(stderr, \"Error writing.\\n\");\n               return EXIT_FAILURE;\n            }\n            int_to_char(rng[nb_packets-1], int_field);\n            if (fwrite(int_field, 1, 4, fout)!=4) {\n               fprintf(stderr, \"Error writing.\\n\");\n               return EXIT_FAILURE;\n            }\n            if (fwrite(output_packet, 1, err, fout)!=(unsigned)err) {\n               fprintf(stderr, \"Error writing.\\n\");\n               return EXIT_FAILURE;\n            }\n            /*fprintf(stderr, \"out len = %d\\n\", err);*/\n         } else {\n            fprintf(stderr, \"opus_repacketizer_out() failed: %s\\n\", opus_strerror(err));\n         }\n      } else {\n         int nb_frames = opus_repacketizer_get_nb_frames(rp);\n         for (i=0;i<nb_frames;i++)","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/src/repacketizer_demo.c#L147-L183","documentation":"In the merge (non-split) code path, the first fwrite call writes a 4-byte big-endian integer encoding the output packet length via int_to_char(). If fwrite returns fewer than 4 bytes, the output stream is broken (disk full, broken pipe, I/O error). The tool exits immediately with EXIT_FAILURE without closing fin/fout, which is a minor resource leak. This write encodes the length of the repacketized output packet that opus_repacketizer_out() just produced.","triggerScenarios":"Disk full; output redirected to a pipe whose reader has exited (SIGPIPE suppressed); network filesystem write failure; removable media ejected mid-write.","commonSituations":"Writing to a full /tmp partition; piping output to `head` which exits early; NFS timeout; running in a CI environment with limited disk quota.","solutions":["Check available disk space before running: `df -h <output_dir>`.","If piping output, ensure the reader consumes all data or handle SIGPIPE.","Write to a local filesystem instead of network mounts for large outputs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Check disk space and output writability before processing\n#include <sys/statvfs.h>\nint check_disk_space(const char *path, unsigned long min_bytes) {\n    struct statvfs vfs;\n    if (statvfs(path, &vfs) != 0) return -1;\n    return (vfs.f_bavail * vfs.f_bsize >= min_bytes) ? 0 : -1;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Free disk space before running large merge operations.","Avoid piping output to commands that may exit early (suppress SIGPIPE if needed).","Write to a local filesystem rather than network mounts."],"tags":["opus","cli","file-io","write-error","repacketizer"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}