Skip to content

Commit ff7f225

Browse files
committed
better handling of edge cases causing panics
1 parent a673dad commit ff7f225

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/gemini/client.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Client {
159159
.ok_or(Error::InvalidHost)?;
160160
let tcp_s = TcpStream::connect(addr).await?;
161161
let mut tls_s = async_native_tls::TlsConnector::new()
162-
.danger_accept_invalid_certs(true)
162+
.danger_accept_invalid_certs(true) // FIXME: handle certs
163163
.connect(host, tcp_s)
164164
.await?;
165165

@@ -205,15 +205,16 @@ impl Client {
205205
};
206206
};
207207

208-
let status: u8 = std::str::from_utf8(&buffer[0..2])?
208+
let status: u8 = std::str::from_utf8(buffer.get(0..2).unwrap_or(&[]))?
209209
.parse()
210210
.map_err(|_| Error::InvalidProtocolData(InvalidStatus.into()))?;
211211

212212
let status = Status::try_from(status)
213213
.map_err(|_| Error::InvalidProtocolData(InvalidStatus.into()))?;
214214

215+
let meta_buffer = &buffer.get(3..meta_end).unwrap_or(&[]);
215216
// Split the part of the buffer containing the meta
216-
let meta = String::from_utf8_lossy(&buffer[3..meta_end]).to_string();
217+
let meta = String::from_utf8_lossy(meta_buffer).to_string();
217218

218219
buffer.truncate(n_read);
219220
buffer.shrink_to_fit();

src/window.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ impl Window {
192192
}),
193193
}
194194
tab_view = (imp.tab_view.clone()) {
195+
set_vexpand: true,
195196
connect_selected_page_notify:
196197
clone!(@weak this => move |tab_view| this.page_switched(tab_view)),
197198
}
@@ -381,6 +382,9 @@ impl Window {
381382
let imp = self.imp();
382383
imp.tab_view
383384
.close_page(&imp.tab_view.page(&self.current_tab()));
385+
if imp.tab_view.n_pages() == 0 {
386+
std::process::exit(0); // TODO: maybe there's a better way for gtk apps...
387+
}
384388
}
385389
fn focus_url_bar(&self) {
386390
let imp = self.imp();
@@ -474,9 +478,9 @@ impl Window {
474478
let hue = hash % 360;
475479
let stylesheet = format!(
476480
"
477-
@define-color view_bg_color hsl({hue}, 100%, 98%);
481+
@define-color view_bg_color hsl({hue}, 100%, 99%);
478482
@define-color view_fg_color hsl({hue}, 100%, 12%);
479-
@define-color window_bg_color hsl({hue}, 100%, 98%);
483+
@define-color window_bg_color hsl({hue}, 100%, 99%);
480484
@define-color window_fg_color hsl({hue}, 100%, 12%);
481485
@define-color headerbar_bg_color hsl({hue}, 100%, 96%);
482486
@define-color headerbar_fg_color hsl({hue}, 100%, 12%);

0 commit comments

Comments
 (0)