Commit b77b77130ad1732903236e327b6f2665c7ade200
1 parent
c119b21b
Exists in
master
and in
3 other branches
Adjustments in selection to help the diagnose of segfaults on print
dialog.
Showing
2 changed files
with
47 additions
and
3 deletions
Show diff stats
src/include/lib3270/selection.h
... | ... | @@ -190,7 +190,7 @@ |
190 | 190 | LIB3270_EXPORT int lib3270_get_selection_rectangle(H3270 *hSession, unsigned int *row, unsigned int *col, unsigned int *width, unsigned int *height); |
191 | 191 | |
192 | 192 | /** |
193 | - * @brief Get selection contents. | |
193 | + * @brief Create a new selection block. | |
194 | 194 | * |
195 | 195 | * @param hSession Session handle. |
196 | 196 | * @param cut Non zero to clear selected contents. |
... | ... | @@ -199,7 +199,19 @@ |
199 | 199 | * @return NULL on error (sets errno), pointer to a rectangle containing the selected area (release it with lib3270_free). |
200 | 200 | * |
201 | 201 | */ |
202 | - LIB3270_EXPORT lib3270_selection * lib3270_get_selection(H3270 *hSession, int cut, int all); | |
202 | + LIB3270_EXPORT lib3270_selection * lib3270_selection_new(H3270 *hSession, int cut, int all); | |
203 | + | |
204 | + LIB3270_EXPORT lib3270_selection * LIB3270_DEPRECATED(lib3270_get_selection(H3270 *hSession, int cut, int all)); | |
205 | + | |
206 | + /** | |
207 | + * @brief Get the length of the selection block. | |
208 | + * | |
209 | + * @param selection Selection block. | |
210 | + * | |
211 | + * @return The length of the selection block. | |
212 | + * | |
213 | + */ | |
214 | + LIB3270_EXPORT size_t lib3270_selection_get_length(const lib3270_selection *selection); | |
203 | 215 | |
204 | 216 | /** |
205 | 217 | * @brief Get bitmasked flag for the current selection. | ... | ... |
src/selection/get.c
... | ... | @@ -31,6 +31,8 @@ |
31 | 31 | #include <lib3270.h> |
32 | 32 | #include <lib3270/session.h> |
33 | 33 | #include <lib3270/selection.h> |
34 | + #include <lib3270/trace.h> | |
35 | + #include <lib3270/log.h> | |
34 | 36 | #include "3270ds.h" |
35 | 37 | |
36 | 38 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
... | ... | @@ -144,8 +146,23 @@ LIB3270_EXPORT char * lib3270_cut_selected(H3270 *hSession) |
144 | 146 | return lib3270_get_selected_text(hSession,0,LIB3270_SELECTION_CUT); |
145 | 147 | } |
146 | 148 | |
149 | +static size_t get_selection_length(unsigned int width, unsigned int height) | |
150 | +{ | |
151 | + return sizeof(lib3270_selection) + (sizeof(lib3270_selection_element) * ((width*height)+1)); | |
152 | +} | |
153 | + | |
154 | +LIB3270_EXPORT size_t lib3270_selection_get_length(const lib3270_selection *selection) | |
155 | +{ | |
156 | + return get_selection_length(selection->bounds.width,selection->bounds.height); | |
157 | +} | |
158 | + | |
147 | 159 | LIB3270_EXPORT lib3270_selection * lib3270_get_selection(H3270 *hSession, int cut, int all) |
148 | 160 | { |
161 | + return lib3270_selection_new(hSession,cut,all); | |
162 | +} | |
163 | + | |
164 | +LIB3270_EXPORT lib3270_selection * lib3270_selection_new(H3270 *hSession, int cut, int all) | |
165 | +{ | |
149 | 166 | if(check_online_session(hSession)) |
150 | 167 | return NULL; |
151 | 168 | |
... | ... | @@ -164,7 +181,10 @@ LIB3270_EXPORT lib3270_selection * lib3270_get_selection(H3270 *hSession, int cu |
164 | 181 | } |
165 | 182 | |
166 | 183 | // Get output buffer. |
167 | - lib3270_selection * selection = lib3270_malloc(sizeof(lib3270_selection) + (sizeof(lib3270_selection_element) * (width*height))); | |
184 | + size_t length = get_selection_length(width, height); | |
185 | + lib3270_selection * selection = lib3270_malloc(length); | |
186 | + | |
187 | + memset(selection,0,length); | |
168 | 188 | |
169 | 189 | selection->bounds.col = col; |
170 | 190 | selection->bounds.row = row; |
... | ... | @@ -172,6 +192,16 @@ LIB3270_EXPORT lib3270_selection * lib3270_get_selection(H3270 *hSession, int cu |
172 | 192 | selection->bounds.width = width; |
173 | 193 | selection->cursor_address = lib3270_get_cursor_address(hSession); |
174 | 194 | |
195 | + debug( | |
196 | + "width=%u height=%u length=%u (sz=%u szHeader=%u szElement=%u)", | |
197 | + selection->bounds.width, | |
198 | + selection->bounds.height, | |
199 | + ((selection->bounds.width * selection->bounds.height) + 1), | |
200 | + (unsigned int) length, | |
201 | + (unsigned int) sizeof(lib3270_selection), | |
202 | + (unsigned int) sizeof(lib3270_selection_element) | |
203 | + ); | |
204 | + | |
175 | 205 | unsigned int dstaddr = 0; |
176 | 206 | |
177 | 207 | for(row=0;row < selection->bounds.height; row++) |
... | ... | @@ -206,5 +236,7 @@ LIB3270_EXPORT lib3270_selection * lib3270_get_selection(H3270 *hSession, int cu |
206 | 236 | |
207 | 237 | } |
208 | 238 | |
239 | + debug("dstaddr=%u length=%u",(unsigned int) dstaddr, (unsigned int) length); | |
240 | + | |
209 | 241 | return selection; |
210 | 242 | } | ... | ... |