segfault in inadyn-mt

Two small suggestions:
Code:
-       if (p_dyndns->p_pidfilename) {
-               if (strlen(p_dyndns->p_pidfilename) != 0) {
+       if (p_dyndns->p_pidfilename && *p_dyndns->p_pidfilename) {
You can use fprintf to write directly to the file:
Code:
-#ifndef _WIN32
-                               if (0<snprintf(pid, 7, "%d\n", getpid()))
-#else
-                               if (0<_snprintf(pid, 7, "%d\n", _getpid()))
-#endif
-                                       obj = fwrite(pid, strlen(pid), 1, fp);
-                               fclose(fp);
+#ifndef _WIN32
+                               fprintf(fp, "%d\n", getpid());
+#else
+                               fprintf(fp, "%d\n", _getpid());
+#endif
+                               obj = fclose(fp);
While fwrite or fprintf may return write errors, in practice such a small amount of data will not be written to the file system immediately, but only at the time of the fclose, so it makes more sense to check that return value. You could also check the return values of both functions.
 
I did not write the pid part of the patch, so probably, I'd not have checked the write return value at all.

But thanks. Very good point.

Bryan
 
Kostenlos!

Statistik des Forums

Themen
248,924
Beiträge
2,305,279
Mitglieder
378,650
Neuestes Mitglied
Factory22