Commit c78a9265 c78a92659a1ae097bd92947aeb68efd88e26d3e4 by Sergey Poznyakoff

Bugfix. Thanks Wojciech for noticing!

1 parent deaa3c28
...@@ -48,6 +48,9 @@ mh_context_read (mh_context_t *ctx) ...@@ -48,6 +48,9 @@ mh_context_read (mh_context_t *ctx)
48 struct stat st; 48 struct stat st;
49 FILE *fp; 49 FILE *fp;
50 50
51 if (!ctx)
52 return EINVAL;
53
51 if (stat (ctx->name, &st)) 54 if (stat (ctx->name, &st))
52 return errno; 55 return errno;
53 56
...@@ -79,6 +82,9 @@ mh_context_write (mh_context_t *ctx) ...@@ -79,6 +82,9 @@ mh_context_write (mh_context_t *ctx)
79 size_t off = 0, n; 82 size_t off = 0, n;
80 FILE *fp; 83 FILE *fp;
81 84
85 if (!ctx)
86 return EINVAL;
87
82 fp = fopen (ctx->name, "w"); 88 fp = fopen (ctx->name, "w");
83 if (!fp) 89 if (!fp)
84 { 90 {
...@@ -117,7 +123,7 @@ mh_context_get_value (mh_context_t *ctx, const char *name, const char *defval) ...@@ -117,7 +123,7 @@ mh_context_get_value (mh_context_t *ctx, const char *name, const char *defval)
117 { 123 {
118 char *p; 124 char *p;
119 125
120 if (header_aget_value (ctx->header, name, &p)) 126 if (!ctx || header_aget_value (ctx->header, name, &p))
121 p = (char *) defval; 127 p = (char *) defval;
122 return p; 128 return p;
123 } 129 }
...@@ -125,6 +131,8 @@ mh_context_get_value (mh_context_t *ctx, const char *name, const char *defval) ...@@ -125,6 +131,8 @@ mh_context_get_value (mh_context_t *ctx, const char *name, const char *defval)
125 int 131 int
126 mh_context_set_value (mh_context_t *ctx, const char *name, const char *value) 132 mh_context_set_value (mh_context_t *ctx, const char *name, const char *value)
127 { 133 {
134 if (!ctx)
135 return EINVAL;
128 if (!ctx->header) 136 if (!ctx->header)
129 { 137 {
130 int rc; 138 int rc;
...@@ -145,6 +153,8 @@ mh_context_iterate (mh_context_t *ctx, mh_context_iterator fp, void *data) ...@@ -145,6 +153,8 @@ mh_context_iterate (mh_context_t *ctx, mh_context_iterator fp, void *data)
145 size_t i, nfields; 153 size_t i, nfields;
146 int rc = 0; 154 int rc = 0;
147 155
156 if (!ctx)
157 return EINVAL;
148 header_get_field_count (ctx->header, &nfields); 158 header_get_field_count (ctx->header, &nfields);
149 for (i = 1; i <= nfields && rc == 0; i++) 159 for (i = 1; i <= nfields && rc == 0; i++)
150 { 160 {
......